Get global JS filter function
-
Hello,
I would like to create some special pages, with posts already filtered on it.
For example :
- I have a taxonomy “Fruit” with “apple, orange, pineapple”
- I have a page “Fruits” with a YMC Filter that filters articles by fruit : there are buttons on it to filter by fruit
-> I would like to know how is it possible to have a page “Apple”, the same as “Fruits”, but with “Apple” already filtered on it ?
Many thanks
-
Hi!
To load specific posts for specific tags (terms) on specific pages, you should select the desired terms in the plugin settings and then click the three dots on the right side of the desired term. A pop-up will open, and inside, select the Default Term option. (The Default Term is applied only for the initial grid load and is not used after filtering or resetting filters.) This will allow you to initially load posts that belong to the default term. We hope this helps.Yes it’s perfect, many thanks !
Good luck!
Hello,
I reopen this thread for a relative question to my 1st question : I have a lot of pages to build based on the question above. It’s a shame to make a lot of filters simply with a different parameter, the default term option that you mentionned. So is there a way to pass this parameter, default term option, for example within the shortcode that displays the filter ? Or another solution ?
Many thanks !
Hi!
Yes, you can use the same filter to display different posts based on different criteria (tags). To do this, you’ll need to use a programmatic approach. If you’re familiar with JavaScript, you should use the plugin API. Here’s a link to the documentation: Global Object API
https://github.com/YMC-22/YMC-Filter#ymcfiltergrid-global-object-api
To do this, you need to enable this option in the plugin’s settings. This is a powerful tool that allows you to control the output using various post selection criteria. One way is to pass the tag ID via a link (URL) and then retrieve it on the desired page by passing it to the corresponding plugin hooks.-
This reply was modified 1 week, 3 days ago by
YMC.
Hi
Yes, it sounds so good to me, I’m familiar with JS, it seems to be the right way to achieve exactly what I want ! Many thanks !
Hi
So, I’m able to interact with the filter by JS (filter by term …etc). I want to use setParams on posts_per_page to display different number of posts depending on my pages. But it doesn’t work. Others setParams works (I tried paged, search …etc), but not posts_per_page. I don’t use any extra “Advanced query” like callbacks for example. So I don’t understand why this parameter doesn’t work. Have you an idea ?
Many thanks !
-
This reply was modified 1 week, 2 days ago by
fredericv.
The posts_per_page parameter will only need to be overridden via the Colback function. All available parameters that can be overridden are listed in the plugin documentation. For everything else, you’ll need to use the Colback function for the filter.
Okay, thanks.
But then, why does thesetParamsparameter exist forposts_per_pagein the API?Because one of my main goals is to display a single filter, adjusting the number of posts displayed based on the page…
-
This reply was modified 1 week, 2 days ago by
fredericv.
You can use the YMCFilterGrid.setParams(params, options = {}) parameter in your scripts. Learn all the settings and parameters for this method in the documentation.
Sorry, I must have misunderstood your last reply…
I’m just trying to use the YMCFilterGrid.setParams({ posts_per_page: 12 }) parameter as shown here. But the number of posts displayed doesn’t change.
Based on your reply, I understood that this setting can only be changed within a callback. Is that correct?Ahhhhh ok !!! The param “per_page” works perfectly !
Maybe the documentation needs to be updated, because it says YMCFilterGrid.setParams({ posts_per_page: 12 }), but this setting doesn’t work! YMCFilterGrid.setParams({ per_page: 12 }) works great 🙂
Many thanks !
Good luck
-
This reply was modified 1 week, 3 days ago by
You must be logged in to reply to this topic.