It’s working perfectly for me. Have you tested this?
@kiwicreative – sorry for not thanking you sooner! I changed tack as I needed to get the project rolled out, but I will investigate soon enough to see if I can solve it. I have a feeling it should work and could be useful, but I had a fallback that did the trick.
All the best
Andy
@kiwicreative I added the code to the block, but this is where I think something more fundamental is going on.
The $posts variable seems to be empty. I have a block that adds custom fields to the page they’re assigned to. That works fine.
What I want to do is pull the same fields into the related page in a block. The if( $posts )
conditional appears to evaluate as false and renders nothing in the block.
@kiwicreative well would you believe it. That works on the page template (yet to test the block).
Yes, they’re simple text fields, but adding the post id pulled them in.
I’ll add it to the block template and see if that works too.
Thanks!
@kiwicreative not sure if I have something more fundamentally wrong somewhere!
I’ve changed it to get_field()
and created a simple page template to test things. If I print_r($posts)
I don’t see any custom field values in the array (not sure if I should), but the custom field values are empty on the page.
Here’s my test page – https://treegrowing.tcv.org.uk/identify/testing-block – the three values (Scientific Name, Family and Scientific Family) should populate from custom fields in the related post – ID 65.
Thanks for your help – much appreciated!
So, just to clarify, I’ve updated the code in the block template and this is it, pasted straight from the site – no leeway for typos!
$posts = get_field('info_from_growing');
if( $posts ) {
foreach( $posts as $post) { // variable must be called $post (IMPORTANT)
setup_postdata($post);
$scientificName = the_field('scientific_name');
$family = the_field('family');
$scientificTreeFamily = the_field('scientific_tree_family');
// do something with the values
}
}
@kiwicreative sorry – I see what you mean – long day 🙂
However, I AM using get_field
to set the $posts
variable. I just typed it wrong in my question above (which would have helped!).
Thanks @kiwicreative but the docs say the_field('author', $p->ID);
and foreach( $posts as $p )
as in there are two ways of doing it. I’ve tried both and neither work…
Does that mean the docs are incorrect?
Rolling back to 5.6.0 and the problem goes away…
@apisklov do you have Toolset Types installed?
Hi folks,
I’ve come across the same issue. Did you get anywhere? Is it Toolset or ACF that’s at fault here? Is there a workaround?
Thanks
Andy
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.