Skip Navigation

[Resolved] View Filter not working as expected for filter by taxonomy of the page

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

Problem: I have a CPT "Program" and a Taxonomy "Program". I have a View of CPT Programs that is set up to filter by the Taxonomy "Program" terms of the current page, but it is not working on Program single post pages.

Solution: Configure the Query Filter so you can use a shortcode attribute to pass the current post's slug into the filter.

[wpv-view name="your-program-post-view" wpvprogramtax="[wpv-post-slug]"]

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

This support ticket is created 6 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
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 2 replies, has 2 voices.

Last updated by Christian Cox 6 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#908359
screenshot 4.png
screenshot 3.png
screenshot 2.png
screenshot 1.png

I am trying to: Display a list of custom posts, filtered by a custom taxonomy.
What is happening: This works fine for the most part, but on one taxonomy page its including two taxonomies instead of just the one.

My view displays a list of custom posts, filtered by a custom taxonomy. This works fine for all but one taxonomy page.

The view filter is set as follows:
Select posts with taxonomy: Programs the same as the page where this View is shown
'Programs' being a custom taxonomy.

I have a page the lists these taxonomies, and a user can click through to a 'program'.
For example, a user clicks the link for '.../program/program-rmct/'
This should show all posts with the taxonomy program of 'program-rmct'.
This works fine on all other programs except this one. For some reason on this particular one, it's including content for the program taxonomy 'program-vclc'

I'm also seeing strange redirects to the home page from time to time when viewing one of the program pages.
It shows a 404, then redirects to home. If I force refresh, then sometimes it starts working again. Not sure if this is related. It's intermittent, and may have just been a caching issue. Not the main concern.

If you take a look at the screenshots attached, I'm showing the following:
- screenshot 1 - shows home page list of all 'program' taxonomies that the user has access to.
- screenshot 2 - shows the program-vclc taxonomy - this is working as expected.
- screenshot 3 - shows the program-rmct taxonomy - note ow the breadcrumbs list "REAL Marketing Core Training, Virtual Coach Learning Centre" - this is a shortcode listing the current taxonomy. Somehow it's including both of these in the view.
- screenshot 4 - shows how I have the view filtering setup

#908572
Screen Shot 2018-06-04 at 5.52.17 PM.png

Hi, as it is set now, the filter is checking the current page, i.e. a Program post, and determining which Program taxonomy terms are associated with the Program Post. Then it's filtering the View of Program Sections by those same Program taxonomy terms. That seems a bit odd, because you would have to have the Program taxonomy applied to the Program post type. If that is your intention, then the current setup is fine. You should verify that the Program post has the appropriate Program terms associated with it in order for the View of Program Sections to filter by the correct terms.

You could do this in a more automated fashion without applying the Program taxonomy to the Program post type. Configure the Query Filter to filter by Program taxonomy term, but set it up so that the term filter is set by a shortcode attribute. Then pass the Program post slug into the View shortcode, something like this:

[wpv-view name="your-program-post-view" wpvprogramtax="[wpv-post-slug]"]

See the attached screenshot for an example of this type of Query Filter. My taxonomy is called "Book Tax" but yours will be "Program" or something else.

This approach means you don't have to associate the Program taxonomy with the Program post type, and you don't have to assign Program terms to each Program post. On the other hand, it also means that you must be sure the Program taxonomy term slugs are identical to their corresponding Program post slugs. In other words, on the /program/program-vclc post page, you want to show Program Section posts that have the Program taxonomy term "program-vclc". But if your term slug is actually "program-vc-lc" then this approach won't work - the slugs of the Program terms and Program posts must be identical.

Let me know if you have questions about this, or if I misunderstood what you want to accomplish.

#908575

One thing I neglected to mention - it's usually a good idea to uncheck "Don't include the current page in query result" in the View editor when the View displays a different post type. Otherwise you can get some unexpected results.