Hi, my filter works if I put the name of the relationship field.
My problem is that I have many group fields with relationship fields inside all with the name “items” so the filter applies to all these fields.
I want to apply the filter only to the group field with the name “link_scope_pages” and in particular to its relation subfield with the name “items”.
From various topics such as wp_query I tried to use the group name “_” name of the subfield relationship “link_scope_pages_items” but this doesn’t work.
Here is my problem.
At the moment I solved it with the key name of the relationship subfield (it seems to be unique), but I wanted to know if there was a solution with the names or even putting conditions inside the filter.
This is my filter that works
function filter_relationship_acf_scope_pages( $args, $field, $post_id ) {
$args = [
'post_type' => 'page',
'meta_query' => [
[
'key' => '_wp_page_template',
'value' => 'tpl-scope.php',
]
]
];
return $args;
}
add_filter('acf/fields/relationship/query/key=field_5f1b0571deda4', 'filter_relationship_acf_scope_pages', 10, 3);
what name should it have?
Array
(
[ID] => 0
[key] => field_5fad1c053194c
[label] =>
[name] => acf[field_5fad1c053194c]
[prefix] => acf
[type] => group
[value] => Array
(
[field_5fad1f55299f4] =>
[field_5fad1c313194d] => 1
[field_5fad1c493194e] => Array
(
[0] => Array
(
[field_5fad1c733194f] => Emergenze
[field_5fad1d7e31954] => 1
[field_5fad643cea81d] => Array
(
[field_5f9c1fb8b4913] => Array
(
[field_5f9c211cb4914] => 6925
[field_5f9c27fab4915] => Scopri di più
)
)
[field_5fad1cde31950] => Lorem ipsum
[field_5fad1cf131951] => Prestiamo soccorso alle popolazioni vittime di emergenze umanitarie, attraverso la distribuzione di beni primari e la ricostruzione. Oltre l’emergenza, creiamo le condizioni perché l’aiuto si trasformi in un percorso di sviluppo e autonomia per le comunità locali.
[field_5fad1dea31955] => 7004
)
[1] => Array
(
[field_5fad1c733194f] => Sviluppo
[field_5fad1d7e31954] => 0
[field_5fad643cea81d] => Array
(
[field_5f9c1fb8b4913] => Array
(
[field_5f9c211cb4914] =>
[field_5f9c27fab4915] =>
)
)
[field_5fad1cde31950] => Test
[field_5fad1cf131951] => Prestiamo soccorso alle popolazioni vittime di emergenze umanitarie, attraverso la distribuzione di beni primari e la ricostruzione. Oltre l’emergenza, creiamo le condizioni perché l’aiuto si trasformi in un percorso di sviluppo e autonomia per le comunità locali. Prestiamo soccorso alle popolazioni vittime di emergenze umanitarie, attraverso la distribuzione di beni primari e la ricostruzione. Oltre l’emergenza, creiamo le condizioni perché l’aiuto si trasformi in un percorso di sviluppo e autonomia per le comunità locali.
[field_5fad1dea31955] => 7007
)
)
)
[menu_order] => 0
[instructions] =>
[required] => 0
[id] => acf-field_5fad1c053194c
[class] =>
[conditional_logic] => 0
[parent] => group_5fad1bae10663
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[layout] => block
[wpml_cf_preferences] => 0
[_name] => featured_blocks
[_valid] => 1
[sub_fields] => Array
(
[0] => Array
(
[ID] => 0
[key] => field_5fad1f55299f4
[label] => Informazioni
[name] =>
[prefix] => acf
[type] => message
[value] =>
[menu_order] => 0
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => field_5fad1c053194c
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[wpml_cf_preferences] => 0
[message] => In evidenza mostra in alto alla pagina subito dopo la testata uno o più blocchi (con metodologia tab) contenenti titolo, descrizione, immagine ed eventuale link se reso visibile della pagina selezionata.
[new_lines] => wpautop
[esc_html] => 0
[_name] =>
[_valid] => 1
)
[1] => Array
(
[ID] => 0
[key] => field_5fad1c313194d
[label] => Attivo
[name] => is_active
[prefix] => acf
[type] => true_false
[value] =>
[menu_order] => 1
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => field_5fad1c053194c
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[message] =>
[default_value] => 0
[ui] => 1
[ui_on_text] =>
[ui_off_text] =>
[wpml_cf_preferences] => 0
[_name] => is_active
[_valid] => 1
)
[2] => Array
(
[ID] => 0
[key] => field_5fad1c493194e
[label] => Blocchi in evidenza
[name] => items
[prefix] => acf
[type] => repeater
[value] =>
[menu_order] => 2
[instructions] =>
[required] => 1
[id] =>
[class] =>
[conditional_logic] => Array
(
[0] => Array
(
[0] => Array
(
[field] => field_5fad1c313194d
[operator] => ==
[value] => 1
)
)
)
[parent] => field_5fad1c053194c
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[wpml_cf_preferences] => 0
[collapsed] => field_5fad1c733194f
[min] => 1
[max] => 0
[layout] => block
[button_label] => Aggiungi blocco
[_name] => items
[_valid] => 1
[sub_fields] => Array
(
[0] => Array
(
[ID] => 0
[key] => field_5fad1c733194f
[label] => Etichetta
[name] => label
[prefix] => acf
[type] => text
[value] =>
[menu_order] => 0
[instructions] =>
[required] => 1
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => field_5fad1c493194e
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[wpml_cf_preferences] => 2
[default_value] =>
[placeholder] =>
[prepend] =>
[append] =>
[maxlength] =>
[_name] => label
[_valid] => 1
)
[1] => Array
(
[ID] => 0
[key] => field_5fad1d7e31954
[label] => Link a pagina
[name] => cta_is_active
[prefix] => acf
[type] => true_false
[value] =>
[menu_order] => 1
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => field_5fad1c493194e
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[wpml_cf_preferences] => 0
[message] =>
[default_value] => 0
[ui] => 1
[ui_on_text] =>
[ui_off_text] =>
[_name] => cta_is_active
[_valid] => 1
)
[2] => Array
(
[ID] => 0
[key] => field_5fad643cea81d
[label] =>
[name] => link
[prefix] => acf
[type] => clone
[value] =>
[menu_order] => 2
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => Array
(
[0] => Array
(
[0] => Array
(
[field] => field_5fad1d7e31954
[operator] => ==
[value] => 1
)
)
)
[parent] => field_5fad1c493194e
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[clone] => Array
(
[0] => group_5f9c1faa3f1a8
)
[display] => group
[layout] => block
[prefix_label] => 1
[prefix_name] => 0
[wpml_cf_preferences] => 0
[_name] => link
[_valid] => 1
[sub_fields] => Array
(
[0] => Array
(
[ID] => 0
[key] => field_5f9c1fb8b4913
[label] =>
[name] => link_to_page
[prefix] => acf
[type] => group
[value] =>
[menu_order] => 0
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => group_5f9c1faa3f1a8
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[wpml_cf_preferences] => 1
[layout] => block
[_name] => link_to_page
[_valid] => 1
[sub_fields] => Array
(
[0] => Array
(
[ID] => 0
[key] => field_5f9c211cb4914
[label] => Collegamento
[name] => post
[prefix] => acf
[type] => post_object
[value] =>
[menu_order] => 0
[instructions] => Seleziona il collegamento dall'elenco.
[required] => 1
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => field_5f9c1fb8b4913
[wrapper] => Array
(
[width] => 50
[class] =>
[id] =>
)
[wpml_cf_preferences] => 1
[post_type] => Array
(
[0] => page
)
[taxonomy] =>
[allow_null] => 0
[multiple] => 0
[return_format] => object
[ui] => 1
[_name] => post
[_valid] => 1
)
[1] => Array
(
[ID] => 0
[key] => field_5f9c27fab4915
[label] => Etichetta pulsante
[name] => label
[prefix] => acf
[type] => text
[value] =>
[menu_order] => 1
[instructions] => Se il campo non viene valorizzato, viene preso automaticamente il titolo.
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => field_5f9c1fb8b4913
[wrapper] => Array
(
[width] => 50
[class] =>
[id] =>
)
[wpml_cf_preferences] => 2
[default_value] =>
[placeholder] =>
[prepend] =>
[append] =>
[maxlength] =>
[_name] => label
[_valid] => 1
)
)
[_clone] => field_5fad643cea81d
[__key] => field_5f9c1fb8b4913
[__name] => link_to_page
[__label] =>
)
)
)
[3] => Array
(
[ID] => 0
[key] => field_5fad1cde31950
[label] => Titolo
[name] => title
[prefix] => acf
[type] => text
[value] =>
[menu_order] => 3
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => field_5fad1c493194e
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[wpml_cf_preferences] => 2
[default_value] =>
[placeholder] =>
[prepend] =>
[append] =>
[maxlength] =>
[_name] => title
[_valid] => 1
)
[4] => Array
(
[ID] => 0
[key] => field_5fad1cf131951
[label] => Descrizione
[name] => description
[prefix] => acf
[type] => textarea
[value] =>
[menu_order] => 4
[instructions] =>
[required] => 1
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => field_5fad1c493194e
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[default_value] =>
[placeholder] =>
[maxlength] =>
[rows] => 3
[new_lines] =>
[wpml_cf_preferences] => 2
[_name] => description
[_valid] => 1
)
[5] => Array
(
[ID] => 0
[key] => field_5fad1dea31955
[label] => Immagine
[name] => image_desktop
[prefix] => acf
[type] => image_aspect_ratio_crop
[value] =>
[menu_order] => 5
[instructions] =>
[required] => 1
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => field_5fad1c493194e
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[wpml_cf_preferences] => 0
[crop_type] => aspect_ratio
[aspect_ratio_width] => 567
[aspect_ratio_height] => 401
[return_format] => array
[preview_size] => full
[library] => all
[min_width] =>
[min_height] =>
[min_size] =>
[max_width] =>
[max_height] =>
[max_size] =>
[mime_types] =>
[_name] => image_desktop
[_valid] => 1
)
)
)
)
[_prepare] => 1
)
Hi,
with the filter you provided me the answer is this below.
The group is simple and is not contained in other groups or a clone.
Array
(
[ID] => 0
[key] => field_5f1b04a650dbe
[label] =>
[name] => acf[field_5f1b04a650dbe]
[prefix] => acf
[type] => group
[value] => Array
(
[field_5fad6bdaa2903] => 1
[field_5f1b0571deda4] =>
)
[menu_order] => 0
[instructions] =>
[required] => 0
[id] => acf-field_5f1b04a650dbe
[class] =>
[conditional_logic] => 0
[parent] => group_5f1b04a64d28d
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[layout] => block
[_name] => link_scope_pages
[_valid] => 1
[sub_fields] => Array
(
[0] => Array
(
[ID] => 0
[key] => field_5fad6bdaa2903
[label] => Automatico
[name] => is_automatic
[prefix] => acf
[type] => true_false
[value] =>
[menu_order] => 0
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => field_5f1b04a650dbe
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[message] =>
[default_value] => 1
[ui] => 1
[ui_on_text] =>
[ui_off_text] =>
[wpml_cf_preferences] => 0
[_name] => is_automatic
[_valid] => 1
)
[1] => Array
(
[ID] => 0
[key] => field_5f1b0571deda4
[label] => Seleziona pagine ambito
[name] => items
[prefix] => acf
[type] => relationship
[value] =>
[menu_order] => 1
[instructions] =>
[required] => 1
[id] =>
[class] =>
[conditional_logic] => Array
(
[0] => Array
(
[0] => Array
(
[field] => field_5fad6bdaa2903
[operator] => !=
[value] => 1
)
)
)
[parent] => field_5f1b04a650dbe
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[post_type] => Array
(
[0] => page
)
[taxonomy] =>
[filters] => Array
(
[0] => search
)
[elements] => Array
(
[0] => featured_image
)
[min] =>
[max] =>
[return_format] => object
[wpml_cf_preferences] => 0
[_name] => items
[_valid] => 1
)
)
[_prepare] => 1
)
Hi yes I solved it using the field key within the group.
But I wanted to know how it works via name if it is possible.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.