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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.