Home › Forums › General Issues › How to also get ACF fields from a get_post loop › Reply To: How to also get ACF fields from a get_post loop
I was able to upgrade the logic of my loop to be manipulated by ACF fields (yeaahh!!!), for example, I can filter the get_post loop by my meta_query of ACF data as shown below…
//BUILD THE LOOP AND LOAD THE POSTS
function ithub_exec_summary_landing_loop() {
//DEFINE OUTPUT VAR
$out = '';
//LOOP - GET AL EXECUTIVE SUMMARIES VIA GET_POSTS()
$args = array(
'numberposts' => -1,
'orderby' => 'modified',
'order' => 'ASC',
'category_name' => 'executive-summary',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'product_owner',
'value' => 'larry',
'compare' => 'LIKE'
),
array(
'key' => 'product_owner',
'value' => 'sally',
'compare' => 'LIKE'
),
array(
'key' => 'product_owner',
'value' => 'bob',
'compare' => 'LIKE'
)
)
);
$mExecSumPosts = get_posts($args);
//REFERENCE LOOP FOR PREVIEWING REVISIONS
if ($mExecSumPosts) {
foreach ($mExecSumPosts as $post):
setup_postdata($post);
//DEFINE LOOP VARS
$mtitle = $post->post_title;
$mpublisheddate = get_the_time('Y-m-d', $post->ID);
$mformateddate = date("l F jS, Y", strtotime($mpublisheddate));
//OUTPUT DATA
$out.= "<div class='row'>";
$out.= "<div class='col'>";
$out.= "<h3><a href='{$post->post_name}'>{$mtitle}</a> <span class='h5 text-secondary'>: Status Date of {$mpublisheddate} | </span></h3>";
$out.= "</div>";
$out.= "</div>";
endforeach;
}
return $out;
}
wp_reset_postdata();
}
…But! How can I output the product owner name (larry, sally, or bob) in this get_posts loop, for each post that is loaded? I have a feeling I may need to create a second get_posts() loop, but don’t know what that looks like from this point forward. Any help would be awesome!
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.