Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

johansenkristian on "custom fields with do_shortcode error if empty"

$
0
0

Hi

I'm using a the plugin Collapse-O-Matic for my custom fields.. Everything works perfect when there is content in the custom fields. But some of my posts don't have any custom fields. Then I'm deleting the custom field in the backend i get these errors:

Warning: Missing argument 1 for do_shortcode(), called in /Users/kristianjohansen/Sites/name/wp-content/themes/eddiemachado-bones-47a7b6d/index.php on line 29 and defined in /Users/kristianjohansen/Sites/name/wp-includes/shortcodes.php on line 190

Notice: Undefined variable: content in /Users/kristianjohansen/Sites/name/wp-includes/shortcodes.php on line 193

Notice: Undefined variable: content in /Users/kristianjohansen/Sites/name/wp-includes/shortcodes.php on line 194

My query looks like this:

<?php $my_query = query_posts('category_name=posts&showposts=-1');?>
  <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
 				<div class="box <?php foreach( get_the_category() as $cat ) { echo $cat->slug . '  '; } ?>">
 					<div class="border">
				<?php the_content(); ?>
				<?php
				$title = get_post_meta($post ->ID, 'title', true);
				$description = get_post_meta($post ->ID, 'description', true);
				$madeby = get_post_meta($post ->ID, 'madeby', true);
					if ( !empty($title))
				{
					echo '<div id="custom-fields">';
					echo '<ul>';
					echo '<li>';
					echo $title;
					echo '&nbsp;';
					echo '&nbsp;';
					echo '&nbsp;';
					echo do_shortcode('[expand]'.$description. '</br>'. $madeby.'[/expand]');
					echo '</li>';
				}
				?>
						</div>
					</div>
				</div>

				<?php endwhile; endif; ?>
				<?php wp_reset_query();?>

The lines where i get the errors in shortcode.php looks like this:

function do_shortcode($content) {
	global $shortcode_tags;

	if ( false === strpos( $content, '[' ) ) {
		return $content;
	}

	if (empty($shortcode_tags) || !is_array($shortcode_tags))
		return $content;

	$pattern = get_shortcode_regex();
	return preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content );
}

Do i have to make a else statement that determining the do_shortcode to leave it empty if there isn't content, or is something in the shortcode.php I'm missing..

I hope someone in hear can help me..

Thanks!


Viewing all articles
Browse latest Browse all 8245

Trending Articles