Home › Forums › Backend Issues (wp-admin) › Load dynamically fields on select change › Reply To: Load dynamically fields on select change
Has this been solved? I am very close to getting this working, but I cannot get the AJAX aspect to work.I see that you said the post_meta needs to be updated, but I am unsure how to do that. Here is the code that I have. Everything works great except for the AJAX updating. Can you please help me.
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices )
{
$choices['Page']['customtemplate'] = 'Custom Template';
return $choices;
}
add_filter('acf/location/rule_values/customtemplate', 'acf_location_rules_values_user');
function acf_location_rules_values_user( $choices ){
$uploads = get_template_directory();
if ($dir = opendir($uploads.'/productstype')) {
$images = array();
while (false !== ($file = readdir($dir))) {
if ($file != "." && $file != "..") {
$images[] = $file;
}
}
closedir($dir);
}
foreach($images as $image) {
$image = str_replace(".php", "", $image);
$choices[ $image ] = $image;
}
return $choices;
}
add_filter('acf/location/rule_match/customtemplate', 'acf_location_rules_match_user', 10, 3);
function acf_location_rules_match_user( $match, $rule, $options ){
global $post;
$current_user = get_post_meta( $post->ID, 'page_template_productstype_select', true );
//$selected_user = (int) $rule['value'];
if($rule['operator'] == "=="){
if($current_user == $rule['value'] ){
$match = true;
}else{
$match = false;
}
}elseif($rule['operator'] == "!="){
if($current_user == $rule['value'] ){
$match = false;
}else{
$match = true;
}
}
return $match;
}
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.