[Resolved] I want to filter previous results from other views on the same page
This support ticket is created 7 years, 4 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I am trying to: use multiple views on the same page. Each of the views are different categories. I would like to have an final view exclude any of the results which have already appeared in the other views. Is this possible or do I need to come up with my own solution?
1. “To have an final view exclude any of the results which have already appeared in the other views.”
Can you please more clarify this? Is this the search view which displays the results?
2. What you expected to see on the front page?
3. What you actually see right now? (preferably with frontend link or screenshot)
Anything, everything, except those posts which have already been displayed in Views 1 and 2.
I need to be able to keep track of posts that have already been displayed and exclude them from other views so I do not have duplicate content on the same page.
There are 2 ways you can exclude posts from a View:
1. Using Offset settings, screenshot attached.
2. Using Query Filter >> Post ID filter, screenshot attached.
If you want to exclude posts dynamically, for example like this:
- if some posts are shown in 1st view.
- then those should be automatically Excluded from the 2nd view.
- then posts shown in 1st and 2nd view should be automatically Excluded from 3rd view.
If you are looking to do it like the above dynamic scenario, then this won’t be possible and we do not have any builtin options to track and exclude it in this way. You would need to create a Custom Shortcode for this purpose. We have some recommended list of service providers here who can help in such cases for you: https://toolset.com/consultant/
Is there any documentation on how to construct a custom shortcode. I know how to create shortcodes and I am confortable working in PHP. I am less familiar with working within Toolset. Do I need to establish a variable in the loop that is collecting each of the post_ids or do I need to hook off of the actual query and collect those that way. If I do the latter, how do I access the values from those shortcodes? Is this done via a URL parameter? Is it possible within a shortcode function (in PHP) to propogate a variable that would be accessible within a view? Are variables just part of PHP global space?
Views offer various API hooks which you can use to modify results through code: https://toolset.com/documentation/programmer-reference/views-filters/
- For your case wpv_filter_query hook might be useful. On the above page there are example php codes given for each hook as well, so you can see how View can be modified.