M
M
matros972018-05-23 08:25:52
WordPress
matros97, 2018-05-23 08:25:52

get_terms not working with ACF?

Hello everyone, I've been trying to figure out for a week what the problem is not working get_terms does not work with ACF, here is the code

$locations = get_terms(array(
    'taxonomy'          => 'locations',
    'meta_query'        => array(
        'relation'      => 'AND',
        array(
            'key'           => 'display_on_page',
            'value'         => true,
            'compare'       => '='
        )
    )
));

I made a custom display_on_page field using the ACF plugin, it just returns an empty array.
I found a solution on the ACF forum, here is the link
, I inserted the code in the functions.php file of my theme
function acf_update_term_meta($value, $post_id, $field) {
    $term_id = intval(filter_var($post_id, FILTER_SANITIZE_NUMBER_INT));
    if($term_id > 0)
        update_term_meta($term_id, $field['name'], $value);
    return $value;
}
add_filter('acf/update_value/name=storemeta_state', 'acf_update_term_meta', 10, 3);
add_filter('acf/update_value/name=storemeta_city', 'acf_update_term_meta', 10, 3);
 
function acf_load_term_meta($value, $post_id, $field) {
    $term_id = intval(filter_var($post_id, FILTER_SANITIZE_NUMBER_INT));
    if($term_id > 0)
        $value = get_term_meta($term_id, $field['name'], true);
    return $value;
}
add_filter('acf/load_value/name=storemeta_state', 'acf_load_term_meta', 10, 3);
add_filter('acf/load_value/name=storemeta_city', 'acf_load_term_meta', 10, 3);

Fields are not developed, tell me what is the problem and how to make it start working?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question