• 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 2 replies - 1 through 2 (of 2 total)
  • You only check if the title is empty before printing out the description.

    You’ll need to add another condition to check that the description is not empty before you print it.

    if ( !empty($description) ) {
       echo do_shortcode('[expand]'.$description. '</br>'. $madeby.'[/expand]');
    }
    Thread Starter johansenkristian

    (@johansenkristian)

    Thank you for you reply.

    It seems to be another problem..

    When i delete the custom field in one of the posts, the posts after don’t react on the css anymore. Like there have to be a custom field otherwise i want work.. I know its hard to imagine but I think i could be something with the shortcode.php as i wrote in the prev message..

    Do you have any ideas of what that could be?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘custom fields with do_shortcode error if empty’ is closed to new replies.