Skip Navigation

[Resolved] Filter taxonomy with taxonomy

This thread is resolved. Here is a description of the problem and solution.

Problem:
Filter taxonomy with taxonomy with first character - glossary, abc filter

Solution:
You can use the taxonomy view's filter hook "wpv_filter_taxonomy_query" with "terms_clauses" hook in order to filter the taxonomy term names with selected first character.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/filter-taxonomy-with-taxonomy/#post-1300543

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_query

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by arisG 5 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#1300015

Hello,

We have followed this ticket and everything is fine.

https://toolset.com/forums/topic/filtering-artist-by-selecting-the-first-letter-of-the-title/

The only problem is that we want to filter another taxonomy instead of posts. we can't find how we will change the query in the following code

add_filter('wpv_filter_query', 'func_filter_by_title', 10, 2);
function func_filter_by_title($query, $setting) {
 
global $wpdb;
     
if($setting['view_id'] == 9999) {
         
        if(isset($_GET['wpvalphabet']) and $_GET['wpvalphabet']!='' ){
             
             
            $first_char = $_GET['wpvalphabet'];
            $postids = $wpdb->get_col($wpdb->prepare("SELECT      ID
                                                        FROM        $wpdb->posts
                                                        WHERE       SUBSTR($wpdb->posts.post_title,1,1) = %s
                                                        AND post_type = '".$query['post_type'][0]."'
                                                        AND post_status = 'publish'
                                                        ORDER BY    $wpdb->posts.post_title",$first_char)); 
                                                         
                  $query['post__in'] = $postids;
                  }
  }
return $query;
}
#1300139

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Do you mean that you want to filter the taxonomy terms rather post title? If yes:

I would like to know, is your view posts view or taxonomy view? Can you please share edit view screenshot of your view?

#1300195
taxonomy_2.JPG
taxonomy_1.JPG

Hello Minesh,

yes, you are right. I want to filter taxonomy terms and I use a taxonomy view.

I have uploaded the images from taxonomy view and I can provide you access to our demo if you want

regards,
Aris G.

#1300317

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - to filter the terms, you need to use the view's filter: wpv_filter_taxonomy_query

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_query

If you do not know how to do it, please share problem URL and access details. I will try to check and fix it on your behalf.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1300543

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now. I've added the following code to "Custom Code" section offered by Toolset.
=> hidden link

add_filter( 'wpv_filter_taxonomy_query', 'func_filter_taxview_by_char', 10, 3 );
function func_filter_taxview_by_char( $tax_query_settings, $view_settings, $view_id ) {
 
    if($view_id == 62736 && isset($_GET['wpvalphabet']) && $_GET['wpvalphabet'] != '' ) {
        $tax_query_settings['name__like'] = $_GET['wpvalphabet'];
    }
    return $tax_query_settings;
}
function func_filter_by_char_caluse($clauses) {
      remove_filter('term_clauses','func_filter_by_char_caluse');
    $splits = explode('}', $clauses['where']);
    $joins = array();
    if(sizeof($splits) == 1) {
      return $clauses;
    }
    foreach($splits as $split) {
      $joins[] = substr($split, 0, strpos($split, '{'));
    }
    $clauses['where'] = join($joins, '') . (sizeof($joins) > 1 ? "%'" : '');
      return $clauses;
}
add_filter('terms_clauses','func_filter_by_char_caluse');

Can you please confirm it works at your end:
=> hidden link

#1301487

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please confirm that solution I shared help you to resolve your issue.

#1301511

Hello Minesh,

Thank you so much for your help. My issue is solved.

Thank you!