Support

Account

Home Forums ACF PRO post objects id pulling in wrong data

Solving

post objects id pulling in wrong data

  • For some reason the excerpt line is just pulling in the content from the post where this is being displayed, instead of the posts it is fetching. The title and permalink portion work as intended. Thoughts?

    
    $post_objects = get_field('acf_selected_projects');
    
    if( $post_objects ): ?>
        <ul style="list-style:none;">
        <?php foreach( $post_objects as $post_object): ?>
            <li style="list-style:none;">
                <h3><a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID); ?></a></h3>
    
    <?php echo get_the_excerpt($post_object->ID); ?>
    
    			<a href="<?php echo get_permalink($post_object->ID); ?>">Read more...</a>
    
            </li>
        <?php endforeach; ?>
        </ul>
    <?php endif;
  • as far as i know :
    get_the_excerpt has no params for ID,
    but you may could try direct output the excerpt via $post_object echo $post_object->post_excerpt;
    if that works as i expect, than you get what you wish.

  • Thanks, I ended up doing the following with some help from another coder.

    
    /* Grab Excerpt Function
    -----------------------------------------------------*/
    function grab_excerpt($str,$length=40,$append='...'){
        $pieces=explode(' ',strip_tags($str));
        $excerpt=implode(' ',array_slice($pieces,0,$length));
        if(count($pieces)>$length)
            $excerpt.=$append;
        return $excerpt;
    }
    

    Then put this in my template :
    <?php echo grab_excerpt($post_object->post_content); ?>

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘post objects id pulling in wrong data’ is closed to new replies.