Home › Forums › Front-end Issues › How to Query Relationship Field › Reply To: How to Query Relationship Field
So, later on, I realized that this is not the right way to go about it. Really what I want is a subset of a CPT called “staff.” I want to get the staff who are presenters on my CPT called “presentations.”
Therefore, it seems like I should do a query on “staff” but just get the ones whose ID is used in the presentations. Right?
$args = array(
'post_type' => 'staff-members',
'posts_per_page' => -1,
'post_status' => 'publish',
'order' => 'ASC',
'orderby' => 'title',
'post__in' => $presenter_id_list
);
However, this starts getting way more complicated than it seems like it should… in order to get the $presentation_id_list data, I can get the distinct list of presenters here:
$presenter_data = $wpdb->get_col(
"SELECT DISTINCT wp_postmeta.meta_value FROM wp_posts
INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
WHERE 1=1 AND wp_posts.post_type = 'presentations' AND (wp_posts.post_status = 'publish') AND (wp_postmeta.meta_key = 'presenters' )
GROUP BY wp_posts.ID ");
But that gives me an array of the serialized “presenter” relationship field. How do I get at the ID in that relationship field??? This seems like it is getting way more complicated than it needs to be. Am I missing something?
Thanks!
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.