Skip Navigation

[Resolved] questions about view's taxonomy filters hooks

This support ticket is created 3 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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9: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: Africa/Casablanca (GMT+01:00)

This topic contains 1 reply, has 2 voices.

Last updated by Jamal 3 years, 6 months ago.

Assisted by: Jamal.

Author
Posts
#2072351

my issue is resolved by the patch and by the update

i'm still using the filter hook to filter term results in specific places.
using a hire' taxonomy the content manager can select easily, as string to filter the terms results of the taxonomy being used as a view filter.
but using the pre hook wpv_filter_taxonomy_frontend_search_get_terms_args<s/trong> with $args['name__like'] = "filtering_string" doesn't allows me to use multiple terms to compare to the terms-query being sent.

another concern is, when i'm using the filter hook, and it changes the "get_terms" for the filter, does it filter the view actual results OR just effects the available filter-form-inputs list?

1. how can i achieve filtering the results after they came as result of "get_terms" (by using the other hook wpv_filter_taxonomy_frontend_search_available_terms) and not like the frontend_search_get_terms_args example (https://toolset.com/forums/topic/view-tax-filter-w-ajax-show-only-available-inputs-displays-all-on-page-load/#post-2068801)

2. and most important - filter by multi values - coming from a different taxonomy or a Types CF field

add_filter( 'wpv_filter_taxonomy_frontend_search_available_terms', 'ycm_modify_available_terms', 10, 3 );
  
function ycm_modify_available_terms( $args, $taxonomy, $view_id ) {
 
    if ($view_id === "9230"){
             
             global $post; 
              $current_channel =  $post->ID; 
              $channel_taxonomy_terms_filtering = get_the_terms( $current_channel , 'helper_taxonomy' );
 
            // if we are filtering input-terms of taxonomy "episodes" filter
 
            if ($taxonomy === "episode"){
 
                     // get only episodes names/slugs similar to some filtering strings or array
                                          ...
                                          ...
                                          ???
             } 
     }   
     return $args;  
} 

for example:

channel cpt post name "Some Channel" - displays a view of video cpt with "category" same as category of the page displayed in, and uses "programs" taxonomy as (user input) secondary filter to show videos belong to specific program.

"Some Channel" is checked with "category" of "some-channel" and in "programs" taxonomy checked with "local-news" and "law-talk".
the view would show videos of "some-channel" category, and the programs filter will show all the programs that assoc' to video results from category "some-channel" - but only ones with "local-news" or "law-talk" in it, like "law-talk-live" and "law-talk-audio" and "local-news-morning" ...

sometimes videos belongs to same category but have 2 programs, and the other program is not in the channel "scope".

so i'm using the programs taxo' on the channel cpt to associate programs to channels and by that filter input-terms of filters in the view.

i thought it would be "lighter" then using a post relationship.

i'm using channel cpt to "create" programs pages. with a radio field as type of channel/program.
the category taxonomy have channels and programs names as terms. category is used also for videos cpt (displayed in view on channels or programs)

big mess - i inherited the situation to fix, on a live site, clean up and rearrange - i know 🙂

( maybe the best way is to make a new cpt for programs, with programs taxonomy, then copy all the relevant parts from the channel cpt content template to the new one.

programs taxonomy will filter the videos view on the program cpt page, and front-end filter of episodes taxonomy.
programs have many2many relationship.

channel cpt will use category taxo' as filter. channel page have programs pages links as a view of related "program" post type.
and display viedos view (same category of channel) and with front-end filter of programs )

#2072489

$args['name__like'] = "filtering_string" does not support to check against multiple value. It only checks against one string. As a workaround, you need to hook into the query and change its SQL query. Or you can directly use an SQL query to get the terms and pass it to the args in the include arguments. Check the possible arguments here https://developer.wordpress.org/reference/classes/wp_term_query/__construct/

The following StackExchange threads may also be interesting for you:
- https://wordpress.stackexchange.com/questions/293389/how-to-return-tags-containing-one-two-or-three-exact-and-specific-words-using-g
- https://wordpress.stackexchange.com/questions/178517/get-terms-name-like-list-categories-according-to-letter

when i'm using the filter hook, and it changes the "get_terms" for the filter, does it filter the view actual results OR just effects the available filter-form-inputs list?
No, it won't affect the results of the view. It will only affect the values of the filter.

how can i achieve filtering the results after they came as result of "get_terms" (by using the other hook wpv_filter_taxonomy_frontend_search_available_terms)
Yes, you can use this hook to change the terms that will be displayed on the filter.

Regarding the current data model, maybe you are right, and using relationships could have more benefits. However, I still don't understand your use case very well to better advise.

Keep in mind that Toolset has some limitations:
- A view cannot filter using two relationships, unless using custom code.
- A view cannot filter a post type, by a taxonomy on another post type. For example, if you use M2M relationship, and you are querying the intermediary post type, you can't filter with the parent's or the child's taxonomies.
- Intermediary post types cannot be assigned a taxonomy. They can only hold custom fields.

I hope this answers your questions. I'll remain at your disposal.