Created
July 7, 2020 18:49
-
-
Save wilnaweb/75be0ff659e9f9f160392f3aa3b612b9 to your computer and use it in GitHub Desktop.
Wordpress - ACF - Dynamic List Values (<select>)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ADD Result search post type in select list ACF Field | |
function mb_acf_load_produto_negocio_field( $field ) { | |
global $post; | |
$field['choices'] = array(); | |
$field['choices'][''] = "Selecione o Negócio"; | |
$marca = get_field('produto_marca',$post->ID); | |
$args = array( | |
'post_type' => 'negocio', | |
'posts_per_page' => '-1', | |
'post_parent' => 0, | |
'meta_query' => array( | |
array( | |
'key' => 'negocio_marca', | |
'value' => array( $marca->ID ), | |
'compare' => 'IN', | |
), | |
) | |
); | |
$objType = new WP_Query($args); | |
foreach($objType->posts as $item){ | |
$field['choices'][$item->ID] = $item->post_title; | |
} | |
return $field; | |
} | |
add_filter('acf/load_field/name=produto_negocio', 'mb_acf_load_produto_negocio_field'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment