Support

Account

Home Forums General Issues Query relationship field in repeater field Reply To: Query relationship field in repeater field

  • I just gave p2p a shot and it indeed does exactly what I want.

    Going through the documentation, I’ve found this (see here):

    // Create connection
    p2p_type( 'YOUR_CONNECTION_TYPE' )->connect( $from_id, $to_id, array(
    	'date' => current_time('mysql')
    ) );
    
    // Delete connection
    p2p_type( 'YOUR_CONNECTION_TYPE' )->disconnect( $from_id, $to_id );

    It is possible to use ACF with my setup as described above (artists custom post types as relationship fields in repeater fields) and then add the above p2p code when I’m adding and deleting artists?

    Because then I can:

    • Use my preferred ACF setup (relationship fields in repeater fields)
    • Which results in that I don’t have to use the p2p admin box for adding artists
    • I can use the p2p queries which solves my querying problem!

    The only question that remains is: what happens when I add an artist in one repeater block, and then add the same artist in another repeater block? The documentation of p2p says about the code above: ‘The advantage of using this API is that it enforces all the rules you set when defining the connection type, such as ‘prevent_duplicates’ and ‘cardinality’.’ So I guess it will check for duplicates? The link to this p2p documentation here.

    I think we’re almost there :-).