Skip Navigation

[Resolved] How to filter a view in a page?

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to reuse the same View on multiple pages of my site, but I would like to filter the View using different taxonomy terms on different pages.

Solution: Use shortcode attributes in your View to define the correct taxonomy filters on each page. Set up your View's Query Filters to filter based on your taxonomy term shortcode arguments.

[wpv-view name="initiatives-in-indicator-pages" wpvcategory="term-slug"]

Relevant Documentation: https://toolset.com/documentation/user-guides/passing-arguments-to-views/

This support ticket is created 5 years, 3 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Benoît 5 years, 3 months ago.

Assigned support staff: Christian Cox.

Author
Posts
#556273

Tell us what you are trying to do?

I want to create an unique view that queries all my post (so without filter but formatted)

I want to use this view for the blog page : that's OK

But I also need to display a selection of posts (filtered by taxonomy) in various pages of my site.
But in the pages, when I add the view in the text editor [wpv-view name="initiatives-in-indicator-pages"]
I don't have the posibility to filter my query to filter the post by taxonomy

I could create different filtered views but then I have to create more than 50 views...

Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/

Is there any solution?

#556282
Screen Shot 2017-08-03 at 4.29.08 PM.png

Sure, you can choose a filter using arguments in the View shortcode. On each page, you can place the View using a different shortcode argument to apply different taxonomy term filters. In your View, you must add a Query Filter that checks a shortcode attribute. If you cannot see the Query Filter section in your View editor, you can enable it in the Screen Options tab at the top of the screen. Here is an example:

[wpv-view name="initiatives-in-indicator-pages" wpvcategory="term-slug"] 

This View would only show posts with the category term "term-slug". Screenshot attached. On another page you could use a different term:

[wpv-view name="initiatives-in-indicator-pages" wpvcategory="other-term-slug"] 

Here's a page with more information about how this works:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

Please let me know if you have additional questions about this.

#556288

Great! Thank you!

#556311
Content Template ‹ SDR17 — WordPress.png
Edit Page ‹ SDR17 — WordPress.png

Hi again Christian,

Sorry to come back but I still have an issue. I have added the parameter to the shortcode.
[wpv-view name="initiatives-in-indicator-pages" wpvcategory="diversity"]
It should display only 3 post with the taxonomy "diversity" (see screenshot)

But all the post are displayed instead. unfiltered. See post list at the bottom
hidden link

Thanks!

#556316
Screen Shot 2017-08-03 at 6.13.25 PM.png

I'm very sorry I just realized that I had the wrong setting selected in the screenshot I posted earlier. Instead of choosing "Set by one URL parameter" in the Filter Query, you should choose "Set by one View shortcode attribute". See the updated screenshot. If you chose URL parameter in the Filter Query options this could be the problem. If not, please take a screenshot showing the Filter Query settings so I can see what you have chosen.

#556434

Now it works!
Thank you very much Christian.