Reputation: 33
I'm using Advanced Custom Fields (ACF) to allow a user to select from a list of pages that will then show a Title, Excerpt and Link for the respective pages.
For some reason this is pulling the excerpt of the current post instead of the related post id. The title and permalink word as desired. I'd love some help.
Thanks, Jeffrey
<?php
/*
// Adding our custom content output
/*
* Loop through post objects (assuming this is a multi-select field) ( don't setup postdata )
* Using this method, the $post object is never changed so all functions need a second parameter of the post ID in question.
*/
add_action( 'genesis_entry_content', 'genesis_project_list', 10, 2 );
add_action( 'genesis_post_content', 'genesis_project_list', 10, 2 );
// The Custom Content output function
function genesis_project_list() {
$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>
<span><?php echo get_the_excerpt($post_object->ID); ?></span>
<a href="<?php echo get_permalink($post_object->ID); ?>">Read more...</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif;
}
genesis();
Upvotes: 1
Views: 1724
Reputation: 758
I don't think get_the_excerpt()
accepts an argument, so you can't pass $post_object->ID
to get that post's excerpt. You'll have to write your own custom function for creating an excerpt. Here's some sample code I've used before (add this to your functions.php):
function custom_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;
}
And then in your template:
<span><?php echo custom_excerpt($post_object->post_content); ?></span>
Upvotes: 2