Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

Advanced custom field how to populate select field

Advanced custom field how to populate select field

In this tutorial we will learn how to dynamically populate Advanced custom field select field in WordPress. I was trying a generate a dynamic select list so when I will create a update it from anywhere else it will automatically display in Advanced Custom Field select field.

Advanced custom field how to populate select field

Advanced custom field how to populate select field PHP Code

First we need PHP array with like, you can use you own custom function, I have used categoryList() in this tutorial.

{
"Programming"=>436,
"Finance"=>437
}

Suppose $category = categoryList(); contains data in format like shown above

function catListACF( $field ) {
//Change this to whatever data you are using.
$category = categoryList();
$field['choices'] = array();
foreach( $category as $key => $item ){
$field['choices'][$key] = $item;
}

return $field;
}
add_filter('acf/load_field/name=cateogry', 'catListACF');

Remember field name slug should be changed in add_filter(‘acf/load_field/name=cateogry’, ‘catListACF’);, here used category.

Use this php  code using in your functions.php file.

You can also read our tutorial on advance custom filed Advanced custom field how to populate select field.

If you have and query or suggestion then please comment, I will reply to fix your problem, if you like our content then you can subscribe to our Youtube channel. If you want to hire me then reach us at our Fiverr.

5 1 vote
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments