Wordpress: the_excerpt not working

I recently updated wordpress and now all content is outputting for this module, except "the_excerpt()"

<?php

function blog_feed_content(){
  ?>
  <ul id="blog_list" class="jscroll">
            <?php
            global $post;
            $args = array('category' => 4 );
            $myposts = get_posts( $args );
            foreach( $myposts as $post ) :  setup_postdata($post); ?>
                <li class="post clearfix" id="post-<?php the_ID(); ?>">
                    <div class="post-content clearfix">
                        <h2 class="post-title"><?php the_title(); ?></h2>
                        <div class="post-date"><?php the_time('F Y') ?></div>
                        <div class="post-text">
                             <?php the_excerpt(); ?> 
                        </div>
                    </div>
                </li>
            <?php endforeach; ?>

    </ul>


  <?php
}

function widget_blog_feed($args){
  extract($args);
  echo $before_widget;
  echo $before_title;?>Blog Feed<?php echo $after_title;
  blog_feed_content();
  echo $after_widget;
}

function init_blog_feed() {
  register_sidebar_widget(__('blog_widget'), 'widget_blog_feed');
}
add_action("plugins_loaded", "init_blog_feed");
?>

Why on earth isn't it outputting this one piece of content?

YOU'RE ALL AWESOME. Thanks.

Answers


setup_postdata is not exactly the same as using a normal WP_Query with the_post() so not all template tags work as expected with this method of displaying posts.

You should rewrite the code to use a custom WP_Query and traditional Loop rather than using a foreach to iterate through post objects.

Something like:

$myposts = new WP_Query('cat=4');
if( $myposts->have_posts() ) : while( $myposts->have_posts() ) : $myposts->the_post(); ?>
    <li class="post clearfix" id="post-<?php the_ID(); ?>">
        <div class="post-content clearfix">
            <h2 class="post-title"><?php the_title(); ?></h2>
            <div class="post-date"><?php the_time('F Y') ?></div>
            <div class="post-text">
                 <?php the_excerpt(); ?> 
            </div>
        </div>
   </li>
<?php endwhile;
wp_reset_query;
endif; ?>

That should point you in the right direction. If you are set on sticking with the foreach and get_posts method you could always use some simple string functions (i.e. substr() to truncate a little excerpt from the post_content property of the $post object, like replacing the <?php the_content(); ?> line with:

<?php echo substr($post->the_content, 0, 80); // displays first 80 chars of post ?>

Need Your Help

cannot install android app because uid changed

android adb

I get this same installation failure Android INSTALL_FAILED_UID_CHANGED and tried deleting my package:

How to store only unique data into Parse.com?

android json parse.com

Am currently working on the android app which fetches data from a url. I need to save some info from it to parse. The data is saved when the user searches for something. So when the user searches the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.