Skip Navigation

[Resolved] Alphabetical view filter term with specific character glossary

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

Problem:
Alphabetical view filter term with specific characgter glossary

Solution:
You need to use the view's filter hook "wpv_filter_taxonomy_query" with default WordPress hook "terms_clauses" in order to filter the view with specific character.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/alphabetical-view/page/2/#post-1241580

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

This support ticket is created 4 years, 11 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)

Tagged: 

This topic contains 23 replies, has 2 voices.

Last updated by ThorstenS967 4 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1241320

Minesh
Supporter

Languages: English (English )

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

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

#1241343

Minesh
Supporter

Languages: English (English )

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

Yes - this works but can you please share problem URL where you added the view and what view I need to work with. Just wanted to double check.

#1241394

Yes.
The views are:
1. Stichwoerter Alpabetical First View
2. Stichwoerter Alpabetical Second View
The view is displayed on:
hidden link

I think the view has to be different from the approach we took here, because like on the site hidden link it has to be a view for the alphabetical letters (maybe as a grid?) and if you click on a letter, the tags should appear for that letter (like on hidden link).

#1241580

Minesh
Supporter

Languages: English (English )

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

Ok - I've added the following code to Toolset's custom code section:
=> hidden link

function func_filter_by_char_caluse( $clauses, $taxonomies, $args ) {
  
  
    if ( ! empty( $args['term_char'] ) ) {
        global $wpdb;

        $char_like = $wpdb->esc_like( $args['term_char'] );

        if ( ! isset( $clauses['where'] ) )
            $clauses['where'] = '1=1';

        $clauses['where'] .= $wpdb->prepare( " AND t.name LIKE %s", "$char_like%");
    }

    return $clauses;
}

add_filter( 'terms_clauses', 'func_filter_by_char_caluse', 10, 3 );


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 == 1591){
 
      $res =  get_terms( 'post_tag', 'term_char='.$_GET['terms-filter'] );
 
      $ids = array();
      foreach($res as $k=>$v):
      	$ids[] = $v->term_id;
      endforeach;
      
    $tax_query_settings['include'] =  	join(",",$ids);
   } 
        
    return $tax_query_settings;
}

Now, if you check the page and click on any character you will find the tag names which will start from that selected character:
=> hidden link

#1241586

Thank you very much!
So, the views are not neccessary? I think, the solution you did with custom PHP code is not doable through (nested) views?
How can I link from a tag to the related article? For example if you click on one of the tags, that it opens the related article?

#1241591

Minesh
Supporter

Languages: English (English )

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

So, the views are not neccessary? I think, the solution you did with custom PHP code is not doable through (nested) views?
==> Well - if you see, we are still using nested views, so it requires nested view + the code to filter the tag names with specified character:
- hidden link
(As you noticed we added a view that displays the alphabets and loop editor section displays the tag title)

How can I link from a tag to the related article? For example if you click on one of the tags, that it opens the related article?
=> I just changed the

  • [wpv-taxonomy-title]
  • To

  • [wpv-taxonomy-link]
  • and now it will open the tag archive.

    #1241619

    Thanks a lot.
    Now I want to display the tags only, if you click on one of the letters and not if you click on the page and haven't clicked on one of the letters yet. I tried this solution: https://toolset.com/forums/topic/if-wpv-post-param-has-a-specific-var-then/
    and replaced it like

    [wpv-conditional if="( '[wpv-search-term param="term-filter"]' ne '' )"]
    <div>[wpv-taxonomy-link]</div>
    [/wpv-conditional]
    

    but this doesn't work.

    New threads created by Minesh and linked to this one are listed below:

    https://toolset.com/forums/topic/split-alphabetical-view-conditional-check-of-tags/

    #1241622

    Minesh
    Supporter

    Languages: English (English )

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

    Well - sir that is another problem.

    I split the ticket here. Please resolve this and we will continue with the split ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summary that belongs to the orignial issue.

    #1241625

    My issue is resolved now. Thank you!

    This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.