Display ACF Field from custom loop array

So I could see that the query doesn’t bring in custom acf fields into the loop which is fine as I can inject them into the array manually but I can’t figure out how to display them after that.

Params($args) with just a simple filter applied

{
'numberposts'	: -1,
'meta_key'	:	'my_filter_checkbox',
'meta_value'	:	'1',
}

Insert my custom acf field (I don’t know if this is the correct way of doing it)

add_filter('cs_looper_custom_getfields', function($result, $args) {
	$posts = get_posts( $args );
	foreach($posts as $post) {
		$post->my_acf_field= get_post_meta(get_the_ID(), 'my_acf_field', true );
	}
}, 10, 2);

check debug. Variable is part of post array.
Current Data:

array(5) {
  [0]=>
  object(WP_Post)#10278 (25) {
  ...
      ["post_type"]=>
    string(4) "post"
  ...
    ["my_acf_field"]=>
    string(13) "Some Text Here"
  }
...

Then within the looper consumer I would hope to use something like
{{dc:post:my_acf_field}} or
{{dc:post:meta key=“my_acf_field”}}

Am I going about this in the correct way? do I need to provide it in the array in a certain way.

Thanks
Sam

Oh no I had a condition set on the text element checking for a different field as I was altering variable names
:man_facepalming:

So to correct above you don’t need to add code to add the ACF fields to the post loop. you just need to not hide it from view.

Anyway I learned a few things!

Hey Sam,

We are glad you’ve figured out a way to resolve your issue.
Thank you very much for letting us know.

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.