Home › Forums › Front-end Issues › Sorting / Querying from One Custom Post › Reply To: Sorting / Querying from One Custom Post
Well your code doesn’t do anything right not to actually fetch the info. 🙂
You need to run it through a custom wp_query AND add the appropriate posts_where filter function as described in the documentation
Take a look at example 4 here: http://www.advancedcustomfields.com/resources/query-posts-custom-fields/
So your code needs to be more like:
<?php
//Get the volunteer posts ID
$post_id = get_the_ID();
//Fetching all shows the volunteer was actor in
$args = array(
'numberposts' => -1,
'post_type' => 'show',
'meta_query' => array(
array(
'key' => 'cast_%_actor',
'compare' => '=',
'value' => $post_id,
)
)
);
$show_actor_query = new WP_Query($args);
?>
<?php if( $show_actor_query->have_posts() ): ?>
<?php while( $show_actor_query->have_posts() ): $show_actor_query->the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php endwhile; wp_reset_postdata(); ?>
<?php endif; ?>
I can’t really write all the code for you because it’d be a bit over the top and I strongly believe in learning by doing 🙂 But I’ll be happy to guide you in what you need to do.
Here you can read more about the WP_Query object
http://codex.wordpress.org/Class_Reference/WP_Query
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.