ricardoE
Support threads created in the last 30 days: 0
Favorite Forum Topics
This user has no favorite topics.
Forum Topics Created
Viewing topic 1 (of 1 total)
Status | Topic | Supporter | Voices | Posts | Freshness |
---|---|---|---|---|---|
Alphabetical filter for a Taxonomy View and Display a custom taxonomy field.
Started by: ricardoE
in: Toolset Professional Support
Problem: I would like to create a View of taxonomy terms and add an alphabetical filter by first letter. Solution: There's nothing exactly like this in Views, but you can achieve it with custom code. // Autores Taxonomy filters function terms_clauses_filtroautores( $clauses, $taxonomies, $args ){ global $wpdb; if( !isset( $args['__ts_first_letter'] ) ){ return $clauses; } $clauses['where'] .= ' AND ' . $wpdb->prepare( "t.name LIKE %s", $wpdb->esc_like( $args['__ts_first_letter'] ) . '%' ); return $clauses; } add_filter( 'terms_clauses', 'terms_clauses_filtroautores', 10, 3 ); // add the custom query parameter for this View. function ts_add_custom_term_argument_function( $tax_query_settings, $view_settings, $view_id ) { $views = array( 5680 ); if( in_array( $view_id, $views ) ) { $tax_query_settings['__ts_first_letter'] = strtolower($_GET['alfautor']); return $tax_query_settings; } } add_filter( 'wpv_filter_taxonomy_query', 'ts_add_custom_term_argument_function', 99, 3 ); Then, create links using each letter of the alphabet. Each letter should point to a URL containing the parameter 'alfautor', like this: <a href="https://mysite.com/autores/">All</a> | <a href="https://mysite.com/autores/?alfautor=a">A</a> | Relevant Documentation: |
2 | 10 | 5 years, 3 months ago |
Viewing topic 1 (of 1 total)