• I’m trying to list posts in a category like so:

    <?php
    global $post;
    $myposts = get_posts('numberposts=2&amp;category=3');
    foreach($myposts as $post) :
    ?>
    <div class="articles"><a href="<?php the_permalink(); ?>"><?php the_content('more'); ?></a></div>
    <?php endforeach; ?>

    But I get these errors:

    Warning: preg_match() expects parameter 2 to be string, object given in dir/wp-includes/post-template.php on line 202

    Catchable fatal error: Object of class stdClass could not be converted to string in dir/wp-includes/post-template.php on line 214

    if I change “the_content(‘more’)” to “the_title()” it works fine, but I want the content, not the title.

    What’s going on here and how can I fix it?

    Thanks!

Viewing 1 replies (of 1 total)
  • Don’t think you need the global statement
    Use setup_postdata($post); after your foreach statement

    Don’t see what causes the error.

Viewing 1 replies (of 1 total)
  • The topic ‘strange the_content error’ is closed to new replies.