Support

Account

Home Forums Front-end Issues List terms which also have a certain relationship Reply To: List terms which also have a certain relationship

  • Hi @jakegonzales

    I believe the code you described only lists the stockist custom posts on the Promotions page. I think you can get the same result by using this code:

    $relationships = get_field("stockists_participating");.

    If you want to group the returned posts from above code, you need to check each of them and group it in an array.

    $thepost_terms = get_the_terms($thepost->ID, 'countries');

    Is used to get all of the terms that belong to a post. After that, you need to loop trough the terms and add a group if it does not exist yet. So if you have a promotion page with these posts in the relationship field:

    Post 1: term 1, term 2
    Post 2: term 2, term 3
    Post 3: term 1
    Post 4: term 3
    Post 5: term 4, term 5

    The result would be like this:

    Term 1: Post 1, Post 3
    Term 2: Post 1, Post 2
    Term 3: Post 2, Post 4
    Term 4: Post 5
    Term 5: Post 5

    Is that what you want?

    If you don’t have time to learn about PHP, I suggest you hire a developer to help you out with it, and I’d recommend looking for one on https://studio.envato.com/ or https://www.upwork.com/.

    I hope this helps 🙂