Ive trying to solve a problem for a few days without luck and am wondering if you could help.
I have 2 Custom Post types, Competitions and Judges.
On the Competitions entry there is a User field type which shows all Authors. And each Author is a CPT Judge entry. So I’m connecting one or maybe more Judges to a Competition. Each Judge has a profile page using single-judges.php on this page I display their personal info.
So if a judge was added to a Competition entry I need to show the Competitions entry title on their profile page. It would be like this:
“Welcome Judge. You are judging the following competitions.”
Then show only the competitions entries that the judge is attached to.
What I need is: If a judge is logged in and viewing their profile page and if he/she has been chosen to judge any Competition entries, display the name of those entries.
The User field Field name is “comp_judges”. Ive tried to implement a solution from this page http://support.advancedcustomfields.com/forums/topic/extracting-a-list-of-posts-based-on-field/ but that returns an empty white screen. Can anyone take a look at that code and see what the issue might be.
There is a tutorial that explains how to do reverse relationship queries located here http://www.advancedcustomfields.com/resources/querying-relationship-fields/
Thanks for that. I did end up implementing this and it does work if using a Relationship field. If using a User field, it doesnt work.
Using the Relationship field, Judge 1 can view his profile page and see what competitions he has a “relationship” with, but he can also go to Judge 2’s page and see Judge 2’s “relationships”. What I need to do is somehow allow each judge to only see the competitions they are related to. So if browsing another persons profile page it wouldnt show anything.
I thought using the User field would allow me to do this because each Judge – which is a CPT entry – is set as the Author as well. But maybe this can be done with the Relationship field as well. Any thoughts on this?
What you need to do is put some PHP at the top of the template file, before get_header(); that gets the current user_id, compares it to the user_id for the profile page and if they do not match then redirect them to there own user profile page. At least that’s probably what I’d do. Anyone that was not logged in and did not have a user profile page I’d probably redirect somewhere else.
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!
© 2022 Advanced Custom Fields.