Home Forums Front-end Issues Bidirectional Relationships With More Than 2 Post Types


Bidirectional Relationships With More Than 2 Post Types

  • Well hello ACF PRO community, here my situation goes,

    I have 1 custom post type named “Contracts”

    and 2 another custom post types named “Payment 1”, “Payment 2”

    Contracts have a relationship field named “payment_contract”
    Also payments have the same field named “payment_contract”,

    “payment_contract” is bidirectional relationship field that I mentioned it in functions.php

    One payment can only be related to one contract but a contract can have more than one payments

    when I use it with only 1 payment type it works.

    But when I try to use it with more than 1 payment type, only one of the payment type works.

    I want to display related contract from the pages of payment 1 and payment 2, but only 1 works,

    I am using the code given in documents

    <?php $related_contract = get_field( 'payment_contract' ); ?>
    <?php if ( $related_contract ) : ?>
    <?php foreach ( $related_contract as $post ) : ?>
    <?php setup_postdata ( $post ); ?>
    ---- contract details go here ---
    <?php endforeach; ?>
    <?php wp_reset_postdata(); ?>
    <?php endif; ?>	

    it works on payment 1 and it returns blank in payment 2,

    before I added payment type 2, payment 1 was working just fine.

    I am wondering what can be wrong

  • Yes while I was searching for an answer I came across your plugin and read all that’s on plugin page, I wonder if it’s different from manually adding code to functions.php?

    And should I remove existing filters in functions.php before trying your plugin

  • not really that different, but it will handle the one to many relationship with a relationship field on one post type and post object fields on multiple other post types.

    Yes, you should remove the other filters, but my plugin will not double, remove anything if you don’t, however it might run before or after your filters depending on your filter priority.

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

You must be logged in to reply to this topic.