Navigation überspringen

[Gelöst] Alphabetical view filter term with specific character glossary

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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 vor 5 Jahren, 7 Monaten. 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)

Dieses Thema enthält 23 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von ThorstenS967 vor 5 Jahren, 7 Monaten.

Assistiert von: Minesh.

Author
Artikel
#1241320

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: 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

Sprachen: Englisch (English )

Zeitzone: 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:
versteckter Link

I think the view has to be different from the approach we took here, because like on the site versteckter 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 versteckter Link).

#1241580

Minesh
Supporter

Sprachen: Englisch (English )

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

Ok - I've added the following code to Toolset's custom code section:
=> versteckter 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:
=> versteckter 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

Sprachen: Englisch (English )

Zeitzone: 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:
- versteckter 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.

    Neue Threads, die von Minesh erstellt wurden und mit diesem verbunden sind, sind unten aufgeführt:

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

    #1241622

    Minesh
    Supporter

    Sprachen: Englisch (English )

    Zeitzone: 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!