Skip Navigation

[Resolved] view tax' filter w/ajax & show only available inputs- displays all on page load

This support ticket is created 3 years, 7 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 14 replies, has 3 voices.

Last updated by Jamal 3 years, 6 months ago.

Assisted by: Jamal.

Author
Posts
#2065023
Screen Shot 2021-05-22 at 4.37.39 PM.png
Screen Shot 2021-05-22 at 4.36.38 PM.png
Screen Shot 2021-05-22 at 3.59.14 PM.png
Screen Shot 2021-05-22 at 3.54.57 PM.png

UPDATED / EDITED

a bug/fix or a missing of the right setting combination

I am trying to:
show only available filter inputs, while using a param-less url to the page.

a pre-filtered view (tax' filter category "same as page" OR shortcode att') together with a custom taxonomy input filter,
showing only available inputs terms when page loads (on page load without any view url params, view info params or filters params).
when ajax input changes even with the "clear-all" submit or "show all" inputs - the unavailable terms are getting hidden as expected because of view ajax-search-settings to hide unavailable inputs).

view settings on attached images.

tried using category filter "same as page" or "shortcode attribute", like:

[wpv-view name="videos-grid" categories="[wpv-post-taxonomy type='category' format='slug']" cached="off"]

- not as expected:
when using url to page (without params) the view inputs are showing all terms.
the unavailable input terms are getting hidden when the url is with this param, even if value is empty: hidden link.../cpt-slug/post-slug/?wpv_view_count=

-- Link to a page where the issue can be seen:
without params, "show available inputs" doesn't work
hidden link

and check same cpt channel page using empty param:

hidden link

"show available inputs" setting also working when using empty param /?wpv_paged=

-- what to look for?

under main section (video player and text box) there is the view, under label "תכניות בערוץ:" (Hebrew translation: "programs on channel"), you see radios for programs tax filter:

"הצג הכל" (Hebrew translation: "show all"), then the terms:
"יומן משפטי" (Hebrew: "law journal")
"עדשה מקומית" (Hebrew: "local scope" ).
there are no "עדשה מקומית" (program tax term of video cpt) videos on this instance - view filtered by category
the terms יומן משפטי - are the only terms should appear on this page.

-- extra info:

content template for cpt channel:

<div class="cat-desc">[wpv-post-body view_template="None"]</div>
[wpv-view name="videos-grid" categories="[wpv-post-taxonomy type='category' format='slug']" cached="off"]

filter on view:

[wpv-filter-start hide="false"]
[wpv-filter-controls]
	<div class="filters-list-row">
      <div class="filter-item form-group">
          <label class="vis-hidden" for="wpv-post-search">[wpml-string context="wpv-views"]חיפוש[/wpml-string]</label>
          [wpv-filter-search-box placeholder="חיפוש..." output="bootstrap"]
          [wpv-filter-submit name="חפש" type="input" output="bootstrap" class="btn-secondary"]
      </div>
      <div class="filter-item form-group" style="">
          [wpv-filter-reset reset_label="הצג הכל" output="bootstrap"]
        </div>  
      [wpv-pagination]<ul class="pagination">
            <li class="page-item">[wpv-pager-prev-page][wpml-string context="wpv-views"]עמוד קודם[/wpml-string][/wpv-pager-prev-page]</li>
            <li class="page-item">[wpv-pager-next-page][wpml-string context="wpv-views"]עמוד הבא[/wpml-string][/wpv-pager-next-page]</li>
        </ul>
      [/wpv-pagination]
    </div>

// channel type "normal channel" display program filter

	[wpv-conditional if="( $(wpcf-channel-type) eq 'channel' )"]
		<div class="filters-list-row">
          [wpv-conditional if="( $(wpcf-channel-with-programs) eq 'programs' )"]
            <div class="filter-item form-group label-top" style="">
                <label class="group-label" for="wpv-program">[wpml-string context="wpv-views"]תכניות בערוץ:[/wpml-string]</label>
              	[wpv-control-post-taxonomy taxonomy="program" type="radios" default_label="<span>הצג הכל</span>" format="<span>%%NAME%%</span>" class="radio-btn" label_class="radio-label" url_param="wpv-program"]
            </div>
          [/wpv-conditional]
         </div>
	[/wpv-conditional]

// channel type "program" display episodes filter

  [wpv-conditional if="( $(wpcf-channel-type) eq 'program' )"]
    <div class="filters-list-row">
        [wpv-conditional if="( $(wpcf-channel-with-episodes) eq 'episodes' )"]
            <div class="filter-item form-group label-top">
                    <label class="group-label" for="wpv-episode">[wpml-string context="wpv-views"]מהדורות:[/wpml-string]</label>
                [wpv-control-post-taxonomy taxonomy="episode" type="select" default_label="הצג הכל" format="%%NAME%%" class="select-btn" url_param="wpv-episode"]
            </div>
        [/wpv-conditional]
    </div>
  [/wpv-conditional]
[/wpv-filter-controls]
[wpv-filter-end]

#2065521

i need a check into this asap, this is a live site of a client and i assured him that toolset is a great solution together with some custom coding.

i need to show only available inputs on page load on this page -
hidden link

this same url with empty param works fine:
hidden link

but the client need to have it working without url param like that
what is the issue here?
all debug info, pre code samples, images, access is available.
please help me get assistance or live support

#2065571

Hello and thank you for contacting the Toolset support.

I logged to the website and activated the views debug tool in Toolset->Settings->Front-end Content->Debug mode, and both URL generate the same debugging information. Either the underlying SQL queries or the query parameters. This means that they return both results, thus should return the same filters based on the current AJAX configuration.

I checked the view (Videos Grid) and the query filter, for Episodes, seems to be corrupt. I can't edit it. Check this screenshot hidden link

I have seen a similar issue in a Hebrew website recently(a month or so) and we were able to fix it by removing the wpml-string shortcodes. For example, by changing this:

<label class="group-label" for="wpv-episode">[wpml-string context="wpv-views"]מהדורות:[/wpml-string]</label>
[wpv-control-post-taxonomy taxonomy="episode" type="select" default_label="הצג הכל" format="%%NAME%%" class="select-btn" url_param="wpv-episode"]

To this:

<label class="group-label" for="wpv-episode">מהדורות:</label>
                [wpv-control-post-taxonomy taxonomy="episode" type="select" default_label="הצג הכל" format="%%NAME%%" class="select-btn" url_param="wpv-episode"]

The wpml-string shortcodes were meant to be used for translating strings, using WPML. However, this is not required anymore. Toolset, now, parses the view and presents the strings to WPML for translation.

I will suggest to remove the wpml-string shortcodes from the view's filter. Update the view. Check the query filters, they should all be editable. If one of them(Episodes) is not editable, please remove it from the query filters and from the Search & Pagination section. Then create it again in the Search & Pagination section and check the view in the frontend.

If this does not help, I'll need to take a copy of the website and debug it locally, let me know if I have you approval.

#2065649
Screen Shot 2021-05-23 at 6.03.20 PM.png
Screen Shot 2021-05-23 at 6.02.54 PM.png

thank you for the quick support and fast check Jamal.

i've removed the wpml shortcodes,
and deleted the filters,
then created them as new,
episodes still unedited and both not working properly on frontend (also programs)

you can see the programs filter ( "תוכניות" ) on a different channel page ( there is conditional-output on the filters of programs and episodes)
hidden link

#2065693

If this does not help, I'll need to take a copy of the website and debug it locally, let me know if I have you approval.

you have my approval

i should mention its a live site

#2065739

i need some quick fix for the meanwhile untill you'll finnish to debug the issue.

how can i filter the filter form inputs (select/radios queries for the taxonomies) with a wp-php filter-hook or action-hook?

#2065759

Unfortunately, we don't have a hook/filter for the search filter values to choose what values to display. However, you may find the following filters interesting. Please check the examples in the documentation:
- wpv_filter_custom_field_filter_original_value: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_custom_field_filter_original_value
- wpv_filter_custom_field_filter_processed_value: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_custom_field_filter_processed_value

I took a copy of your website and I'll get back to you as soon as I have something to share.

In the meanwhile, I am keen to think that wrapping some filters inside conditional may contribute to the cause of this issue. I would suggest to generate the filters on every page, but hide them using CSS. For example, using a class "hidden", and using this CSS:

.hidden{
    display: none;
}

You can do the following for "program" taxonomy filter:

// channel type "normal channel" display program filter
        <div class="filters-list-row [wpv-conditional if="( ( $(wpcf-channel-type) ne 'channel' ) OR ( $(wpcf-channel-with-programs) ne 'programs' ) )"] hidden [/wpv-conditional]">
            <div class="filter-item form-group label-top" style="">
                <label class="group-label" for="wpv-program">תכניות בערוץ:</label>
                [wpv-control-post-taxonomy taxonomy="program" type="radios" default_label="<span>הצג הכל</span>" format="<span>%%NAME%%</span>" class="radio-btn" label_class="radio-label" url_param="wpv-program"]
            </div>
         </div>
#2065821

thank you, i'll try the css approach.

but, i checked the view with no conditional output , and its still have a problem with "episodes". (maybe because it's a flat taxo? or term slugs in hebrew?)
and now checking a new view with page reload.
[wpv-view name="videos-flex-grid-for-channel-page" cached="off"]
pre-filtered to one category "משפט" (Hebrew: "law")
test page:
hidden link

wpv_filter_custom_field_filter - that will work with taxonomy filter?

#2066613

No. That filter is only for custom fields. My apologies for missing that.

For taxonomy filters you may find the following hooks interesting:
- wpv_filter_tax_filter_include_children
- wpv_filter_taxonomy_frontend_search_available_terms
- wpv_filter_taxonomy_frontend_search_get_terms_args

Unfortunately, I could not find the cause of the issue or fix it. I am escalating this issue to our 2nd Tier for further assistance. I'll get back to you as soon as possible.

#2067523

This issue is now escalated to the developers. I'll get back to you as soon as we have something to share.

#2068559

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

Jamal is off today, let me jump in to say that a patch with a fix has been made available, please see this erratum for details:

https://toolset.com/errata/view-setting-show-only-filter-options-that-would-produce-results-not-working-correctly/

Let us know if that helps.

#2068801

the content template of channel displays:
VIEW (id: 9230) of cpt video,
video cpt have a taxonomy of episode that the video is a part of.

we use a dropdown input as taxo' view-filter,

to manually filter the terms i can use wpv_filter_taxonomy_frontend_search_get_terms_args filter to change get_terms to use $args['name__like'] to be compared with the channel program taxonomy term.

with the channel's taxonomy term of program we can filter the episode filter terms that have a similar name.

this test channel have the taxonomy program term set to "עדשה מקומית"
so the view will show dropdown with "episodes" terms that are similar to "עדשה מקומית"
(like: "עדשה מקומית 01" , "עדשה מקומית 02" , "עדשה מקומית 12"... but not: "יומן משפטי 01", "יומן משפטי...").

hidden link

in the wpv filter hook i need the current post/page id where the view is located, how i can get it?

with "global $post;" or toolset function?

here is my initial code for the hook you suggested to use:
wpv_filter_taxonomy_frontend_search_get_terms_args


add_filter( 'wpv_filter_taxonomy_frontend_search_get_terms_args', 'ycm_modify_get_terms_args', 10, 3 );
 
function ycm_modify_get_terms_args( $args, $taxonomy, $view_id ) {

	if ($view_id === "9230"){
            

             global $post;                     // what will get me the current page/post id (that the view is in), would this work?
		
            //get current channel/page id
              $current_page =  $post->ID; 

            // get the page taxonomy 'program'  term slug

              $channel_program_terms = get_the_terms( $current_page , 'program' );

            // if taxonomy filter of episodes

		if ($taxonomy === "episode"){

                     // get only episodes names similar to the name of program term

			$args['name__like'] =  $channel_program_name[0];

			return $args;
		}	
	}	
} 
#2070871

Indeed, you should use "global $post;" to get the current post. You can also use the $_SERVER object, get the "HTTP_REFERER" and then get the post's ID from the URL.
- hidden link
- https://developer.wordpress.org/reference/functions/url_to_postid/

I wonder if you have been able to test the patch suggested by @Nigel! If you did not, can you test with the latest release of Toolset Views 3.5.3, released yesterday? Click on "Check of updates" on the Toolset Installer page to force a version check.

I'll remain at your disposal.

#2071991

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 )

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

https://toolset.com/forums/topic/questions-about-views-taxonomy-filters-hooks/

#2072355

Awesome, I am glad we could help.

However, for support rules, we are able to handle only one issue at a time. This helps us to bring you a better service and also helps other users to find all the information here exposed. For that reason, I have created another ticket about your last questions and I'll be posting my replies there.