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:
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 :-).
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.