Hi,
Is it possible to dynamically set location for custom fields ?
Instead of :
'location' => array (
array (
array (
'param' => 'page',
'operator' => '==',
'value' => '1696',
),
),
array (
array (
'param' => 'page',
'operator' => '==',
'value' => '1762',
),
),
),
something like :
foreach($ids as $id){
'location' => array (
array (
array (
'param' => 'page',
'operator' => '==',
'value' => $id,
),
),
}
I can’t find how to write it inside PHP field generated code. I want to do that cause I can get ids of my translated pages (Polylang) so I want to affect dynamically my customs fields to these pages.
Maybe can I reaffect location after…? (how…?)
Thanks for any help.

I believe you can do it like this:
if( function_exists('acf_add_local_field_group') ):
$ids = array('66','691');
$args = array (
...
...
...
'location' => array (
array (
array (
'param' => 'page',
'operator' => '==',
'value' => '815',
),
),
),
...
...
...
);
foreach( $ids as $id ){
$args['location'][] = array (
array (
'param' => 'page',
'operator' => '==',
'value' => $id,
),
);
}
acf_add_local_field_group($args);
endif;
I hope this helps.
Thanks a lot.
I’ll come later to say if it allows me to perfectly use Polylang with ACF.
So, last but not least :
It works ^^
I can now dynamically assign my ACF custom fields in each Polylang language, thanks to you.
The topic ‘Loop on location fields : dynamically creation’ is closed to new replies.
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.