Support

Account

Home Forums Front-end Issues How to detect if a post has an Advanced Custom Field Relationship field set and

Unread

How to detect if a post has an Advanced Custom Field Relationship field set and

  • I’m creating a menu bar that lists all of the posts titles and I want the ACF Relationship field to act as a subpage field on some of the posts. If a relationship field is set on a certain post, it will show up under which post it’s set (will look like a child) and it will exclude it on the main list (kind of like the parent list).

    Sample expected output:

    Black
    – Avocado
    – Beans
    Blue
    Green
    – Broccoli
    – Spinach
    Yellow
    Current output where the supposed sub posts is duplicated on the parent list:

    Avocado
    Beans
    Broccoli
    Black
    – Avocado
    – Beans
    Blue
    Green
    – Broccoli
    – Spinach
    Yellow
    Spinach

    This is my code. I was trying to put all of the IDs that has a relationship field set so that when I test it on in_array, it will exclude it. The problem is that the $rel = get_field(“relationship”) only sets on posts that I call the parent posts and not the child posts so I can’t exclude them.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.