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!
We've just released ACF 5.12.3 with a security fix to prevent arbitrary file uploads to forms with ACF fields.— Advanced Custom Fields (@wp_acf) July 14, 2022
Now that we've released this update, we recommend updating your sites as soon as possible.
© 2022 Advanced Custom Fields.