I’m working on this site:
(temp URL so might be shut down by in Jan 2014).
I’ve got custom post types Speaker and Sessions. They’re related to each other via relationship fields. One speaker can deliver multiple sessions and more than one speaker can deliver the same session (many to many).
BUT, a speaker may only be giving a few of his/her sessions at a specific Event. I have Events defined as a taxonomy (created using CPT-onomies). I want to be able to check the context on the site, and depending on where the page is being loaded from, show ONLY the sessions from a given year.
Here is what i have so far (on a speaker-type post, trying to link to their sessions):
<?php $posts = get_field('spk_sessions'); // get my relationship fiel if( $posts ): ?> <b> Ok!</b> <!-- we got a value back --> <ul> <?php foreach( $posts as $post_object): ?> <li>Session found: <a href="<?php echo get_permalink($post_object->ID); ?>"> <?php echo get_the_title($post_object->ID); ?></a> <!-- get the title of the related post --> <span>Post Object Custom Field: <?php the_field('subtitle', $post_object->ID); ?></span></li> <!-- get the custom field "subtitle" of the related post --> <?php endforeach; ?> </ul> <?php endif; ?> </div>
This code will pull out all the sessions related to a speaker post, but it pulls them all, and I can’t see how to filter them based on the categories of the Session. There is nothing in the title or the fields themselves I can filter on, just categories.
Basically I need a “if the related item has category X on it, then…” statement.
This is all in my Single.php at the moment. If someone has a better idea of how to do this using different templates (one per post type would make sense) that would also be great. Right now I am putting everyting in Single.php.
Thanks for all the info, but I’m a bit overwhelmed by it all and can’t understand how all the data is related with ACF and how I can help.
Can you please edit your topic and wrap all code in the ‘code’ button, also, can you please attach some screenshots which show how all the data is related?
I´ve editted the post to try to make it clearer and used the “code” button.
It´s related to ACF because I created all my custom fields with it, and because I´m trying to follow this example:
Thanks for the follow up.
Can you please attach some screenshots to show the edit screens for all post types and taxonomies involved?
It is important to see where the relationship field is and how all the data is related.
I can see that the issue revolves around categories, but these arn’t mentioned until the end and I don’t understand how they are used. Perhaps you can describe this a bit more? Screenshots will be great to show how all the data is related
You must be logged in to reply to this topic.
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!
© 2019 Advanced Custom Fields. Subscribe