Home › Forums › General Issues › Relationship field conditional logic
Hi folks,
I’m curious to know if this is possible. I have a relationship field set up on ‘Home’ which is called ‘Featured on homepage?’. On my ‘Home’ template I want to pull in both image and strapline field. I could easily add an image and strapline field to EVERY page, but this seems ineffective.
I am wondering if a page is selected from the ‘Featured on homepage?’ relationship field, it could add an image and strapline field to those pages.
This almost sounds like some conditional logic. Something like ‘Show this field group if ‘page’ is ‘Featured on homepage”…
Any ideas?
Thanks,
R
Hi,
Yes, conditional logic is what you want.
You would do something like:
if (get_sub_field(‘menu_type’) == ‘Featured’) {
// add your fields here
}
The function will vary depending on what you’re checking against (radio or checkbox), or what level your field sits at in your field group.
Check the docs for how reference either of those fields. That should get you started.
Hi @rdck
It is not possible for a location or conditional logic rule to detect a value from another field group.
The only thing I can think of is changing the logic around so that instead of selecting the ‘featured’ posts from the home page, you tick a checkbox on the post you want featured.
This way, once you check this box, you can have conditional logic show some more image fields, etc.
You will need to change the code in your home page template, to query all posts and find the ones which have this checkbox ticked. You can find some code examples for this on the true_false
docuemntation page.
Hope that helps.
Thanks
E
Thanks @elliot – I didn’t think it would be possible. Neat idea, I suppose… although could never probably work in practice. I had originally started with your solution, but changed it as I wasn’t too keep on a checkbox appearing on every page (as I need to sort the order and my tree hierarchy is a little complex) but I’ll think of something 🙂
Thanks again and keep it up.
-R
The topic ‘Relationship field conditional logic’ is closed to new replies.
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.