Support

Account

Home Forums Front-end Issues Backreference for reference field?

Helping

Backreference for reference field?

  • On the site I’m currently working on, I have a CPT called “works” and another one called “clients”. The clients have a repeater field to attach works. Works again have a taxonomy “services” with terms like “design”, “code” and so forth.

    What’s the most efficient way to get all clients that have work attached which was tagged with eg. “code”? Is there some sort of backreference or would I have to iterate over all clients and their works and filter them out manually?

    Ideally I’d load the term “code” and then all the works related and eventually get to the client.

  • Hi @noxoc

    Thanks for the question. Using the repeater field, it will not be possible to query the data as you have asked.

    However, it is possible to do so using a plugin called posts 2 posts. This will replace the repeater field on the clients CPT and allow you to connect the client to work.

    Then you can use normal WP_Query to get the posts. The posts 2 posts plugin contains new parameters for the WP_Query so you can ask for posts that are connected to works and then also add in the work tax_query.

    It will be a bit tricky, but it will be possible.

    Thanks
    E

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Backreference for reference field?’ is closed to new replies.