• Resolved tempuswebdesign

    (@tempuswebdesign)


    Hello,

    Thank you very much for the plugin. We have already looked around in the forum and found some “hooks”. Unfortunately, we have not yet been able to make the desired changes. On the page we have an ACF checkbox with Label and values displayed:

    plan_a : Plan A
    plan_b : Plan B

    We currently get the Value (plan_a and plan_b) displayed in the filter. At this point we would like to have the labels displayed. For this we have used the following code:

    add_filter('wpc_filter_post_meta_term_name', 'wpc_custom_term_name', 10, 2);
    function wpc_custom_term_name($term_name, $e_name){
    if( $e_name === 'plans' ){
    $term_name = get_the_title( $term_name );
    }
    return $term_name;
    }

    Unfortunately it does not work.

    It would also be nice if we could adjust the URL structure. How can we change this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author stepasyuk

    (@stepasyuk)

    Hello @tempuswebdesign

    Thank you for using Filter Everything plugin. In your case you can try to use next code. Don’t forget to edit it with your ACF field meta key:

    add_filter( 'wpc_filter_post_meta_term_name', 'wpc_acf_labels_instead_of_values', 20, 2 );
    function wpc_acf_labels_instead_of_values( $term_name, $meta_key )
    {
        // your ACF-field meta keys
        $keys_with_labels = ['my_first_meta_key', 'my_second_meta_key', 'my_third_meta_key'];
    
        if ( in_array( $meta_key, $keys_with_labels ) ) {
            if( function_exists('get_field_object') ){
                $field = get_field_object( $meta_key );
    
                $new_choises = [];
                if( isset( $field['choices'] ) && ! empty( $field['choices'] ) ){
                    foreach ( $field['choices'] as $key => $value ){
                        $new_key = mb_strtolower($key);
                        $new_choises[$new_key] = $value;
                    }
    
                    $term_name_test = mb_strtolower( $term_name );
                    if( isset( $new_choises[$term_name_test] ) ){
                        $term_name = $new_choises[$term_name_test];
                    }
                }
            }
        }
    
        return $term_name;
    }
    Thread Starter tempuswebdesign

    (@tempuswebdesign)

    really Perfect!

    Thank you very much!

    Thread Starter tempuswebdesign

    (@tempuswebdesign)

    Hello,
    the script works perfectly, but only temporarily. After a short time, the value values are visible. What could be the reason for this? As soon as a post is reopened and saved again, the label values are displayed again.

    I have the same problem, I mean that the filters display the value instead of the label. For example, for the ACF field with key shop_area, these are the values and the labels:

    Spain_south : South of Spain
    Spain_north : North of Spain
    France_south : South of France
    France_north : South of France

    However, the filters of the plugin show:

    Spain_south (14)
    Spain_north (26)
    France_south (25)
    France_north (32)

    I have tried to add your code (from your last comment on March, 3rd) in functions.php but it has not worked.

    add_filter( 'wpc_filter_post_meta_term_name', 'wpc_acf_labels_instead_of_values', 20, 2 );
    
    function wpc_acf_labels_instead_of_values( $term_name, $meta_key )
    
    {
    
    // your ACF-field meta keys
    
    $keys_with_labels = ['shop_area','shop_ranking'];
    
    if ( in_array( $meta_key, $keys_with_labels ) ) {
    
    if( function_exists('get_field_object') ){
    
    $field = get_field_object( $meta_key );
    
    $new_choises = [];
    
    if( isset( $field['choices'] ) && ! empty( $field['choices'] ) ){
    
    foreach ( $field['choices'] as $key => $value ){
    
    $new_key = mb_strtolower($key);
    
    $new_choises[$new_key] = $value;
    
    }
    
    $term_name_test = mb_strtolower( $term_name );
    
    if( isset( $new_choises[$term_name_test] ) ){
    
    $term_name = $new_choises[$term_name_test];
    
    }
    
    }
    
    }
    
    }
    
    return $term_name;
    
    }

    ?How can we make it work?


    • This reply was modified 1 year, 10 months ago by MPasc.

    Hello again,

    @stepasyuk , please, could you give us an answer please? We bought the plugin months ago and it has caused different troubles until now. We can’t find a way to solve this one this time.

    We would really appreciate your help to solve this issue in this plugin.

    Regards,

    Plugin Author stepasyuk

    (@stepasyuk)

    Hello @mpasc

    I’m sorry for the late response.

    In general here is support forum for the Free version only, if you use PRO, please write your support request in the comments section of the page, where you purchased PRO and it will be processed as soon as possible.

    Thank you. Regards.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Acf Field Checkbox change the Value to Label’ is closed to new replies.