Do you mean you want to get the custom field value from inside a custom shortcode? I believe you can do that by passing the current post ID to the
get_field() function like this:
// Get the current post object first global $post; $location = get_field('location', $post->ID);
To get the related posts, you can always query them based on custom field value like this:
// get the value without the formatting so we can search it in the database $location = get_field('location', $post->ID, false); $posts = get_posts(array( 'numberposts' => 5, 'post_type' => 'custom-post', 'meta_key' => 'location', 'meta_value' => $location ));
This page should give you more idea about it: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/.
I hope this helps 🙂
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!
© 2023 Advanced Custom Fields.