Home › Forums › Front-end Issues › CPT Loop not returning get_field but does get_post_meta › Reply To: CPT Loop not returning get_field but does get_post_meta
$post->ID does return value in the previous code yes. I tried with and without $post->ID appended to get_field call.
This page has a good summation of why I was using a separate WP_Query class object – http://www.binarymoon.co.uk/2010/03/5-wordpress-queryposts-tips/
Using a get_posts approach did not change the result but included for future reference anyone else – based closely off the example on get_posts template tag codex page.
$args = array( 'post_type' => 'highlight',
'posts_per_page'=> $count,
);
$highlights = get_posts( $args );
if (count($highlights)) {
$output = "<div id='highlights'><ul>";
foreach ( $highlights as $post ) : setup_postdata( $post );
$output .= "<li>";
$output .= get_field('highlight_call_to_action', $post->ID) . "<br/>";
$output .= get_field('highlight_call_to_action') . "<br/>";
$output .= get_post_meta($post->ID, "highlight_call_to_action", true) . "<br/>";
$output .= "</li>";
endforeach;
$output .= "</ul>";
wp_reset_postdata();
}
In either loop format case using get_field_object with / without the preceeding _ returns a blank shell response. Whether $post->ID is appended or not. Glad to have a temporary working solution, but would obviously prefer to make use of the ACF output fields as I get into more advanced uses with it.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.