Skip Navigation

[Resolved] How to create a taxonomy view automatically filtered by the current Page “Post Title”

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

Problem: I have created over a thousand custom Pages that represent each term in a taxonomy. On each Page, I would like to insert a View that is filtered by comparing the Page Title to the term name.

Solution: It's probably best to use the page slug instead of title, since slug is sanitized for comparisons and will be more unique than title. With that in mind, you can use the wpv-post-slug shortcode and the $current_page operator to access the current Page's slug. Pass that value into the wpvcategory attribute in your View, and configure your View to use a taxonomy term Query Filter where the term is supplied by a shortcode attribute. Insert the View in your Page Content Template or Template Layout using the following shortcode:

[wpv-view name="view-name" wpvcategory="[wpv-post-slug id='$current_page']"]

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

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

Last updated by AtefR7377 6 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#601205

Hi,
I have hundreds of pages to create.I use CSV to create them in bulk.

Each page is titled the same as a taxonomy term. (for example, a page called: Guitar, is corresponding to a category called "Guitar")
Each page is used to display the posts of that taxonomy term.

I am trying to create a view that takes the page title automatically and shows the posts that has the taxonomy that is equal to that page title.

so for example:
instead of me adding this view to each of the hundreds of pages, and replace xxxx with the category name:

[wpv-view name="view-name" wpvcategory="xxxx"]

I want to end up with something like:

[wpv-view name="view-name" wpvcategory="{page_title}"]

so if the page is titles "guitar", the result is a grid of posts that are under category "guitar"..etc

thanks

#601207

Hi,
I created a view that shows "posts" and chose to use the argument in the shortcode method.
I tried the following variations, none of them worked:

[wpv-view name="automatic results 1" wpvcategory="[wpv-post-title]"]
[wpv-view name="automatic results 1" wpvcategory="wpv-post-title"]
[wpv-view name="automatic results 1" wpvcategory=[wpv-post-title]]
[wpv-view name="automatic results 1" wpvcategory="[wpv-post-title output='raw']"]
[wpv-view name="automatic results 1" wpvcategory="wpv-post-title" output='raw']
[wpv-view name="automatic results 1" wpvcategory=[wpv-post-title output='raw']]
[wpv-view name="automatic results 1" wpvcategory="[wpv-post-title output="raw"]"]
[wpv-view name="automatic results 1" wpvcategory="wpv-post-title" output="raw"]
[wpv-view name="automatic results 1" wpvcategory=[wpv-post-title output="raw"]]
[wpv-view name="automatic results 1" wpvcategory="[wpv-post-title output=raw]"]
[wpv-view name="automatic results 1" wpvcategory="wpv-post-title" output=raw]
[wpv-view name="automatic results 1" wpvcategory=[wpv-post-title output=raw]]
[wpv-view name="automatic results 1" wpvcategory="[wpv-post-title output='sanitize']"]
[wpv-view name="automatic results 1" wpvcategory="wpv-post-title" output='sanitize']
[wpv-view name="automatic results 1" wpvcategory=[wpv-post-title output='sanitize']]
[wpv-view name="automatic results 1" wpvcategory="[wpv-post-title output="sanitize"]"]
[wpv-view name="automatic results 1" wpvcategory="wpv-post-title" output="sanitize"]
[wpv-view name="automatic results 1" wpvcategory=[wpv-post-title output="sanitize"]]
[wpv-view name="automatic results 1" wpvcategory="[wpv-post-title output=sanitize]"]
[wpv-view name="automatic results 1" wpvcategory="wpv-post-title" output=sanitize]
[wpv-view name="automatic results 1" wpvcategory=[wpv-post-title output=sanitize]]
#601323

Each page is used to display the posts of that taxonomy term.
You know this is exactly what WordPress Archives are designed to do, right? Term archives are built into WordPress and you do not need to create separate custom Pages with Views for each term. If you're aware of that, and need to use Pages for some specific reason, that's fine, I just wanted to make sure you're aware that you may be creating a lot of extra work for yourself using this approach.

If you want to use the current Page's post title in a shortcode, I suggest you use the wpv-post-title shortcode with the $current_page operator in its id attribute:

[wpv-post-title id='$current_page']
[wpv-view name="automatic results 1" wpvcategory="[wpv-post-title id='$current_page']"]

But it seems like you would use the post slug, since it would be uncapitalized and sanitized. As long as the page slug matches the term slug, this should work:

[wpv-view name="view-name" wpvcategory="[wpv-post-slug id='$current_page']"]
#601455

Hi Christian,

thanks for your comprehensive response. Yes I know that this is the role of the archive pages. however, I have multiple categories, each category needs a totally different layout, therefore using archives is not the optimum solution for me.

however, your solution works perfectly with me.

much appreciated.

#679409

Hi Christian,

Following on from my question before.

Now I have a CPT called "sermons", and a custom taxonomy called "Series".

some sermons will be individual posts, and some sermons will be grouped under the "series" taxonomy. (e..g a series about the book of Genesis, can have 5 posts, all have the custom taxonomy "Genesis").

I will create a post (from the same sermons CPT) for the series. the post title will be identical to the series name. however, slug will not be identical as slug is governed by the 256 characters, and the Arabic characters get encoded in the slug).

I want to create a view that takes the post title and use it automatically to create a view of the sermon posts that have this taxonomy term.

The code I used doesn't give anything. I have the code wrapped in a conditional, but even without the conditional, it still doesn't give any results.

here are the code variation I tried:

[wpv-conditional if="( '[wpv-post-type]' eq 'sermon' ) AND ( $(wpcf-is-this-a-series) eq '1' )"]
[wpv-view name="series-view" wpvseries="[wpv-post-title]"]
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-type]' eq 'sermon' ) AND ( $(wpcf-is-this-a-series) eq '1' )"]
[wpv-view name="series-view" wpvseries="[wpv-post-title id='$current_page']"]
[/wpv-conditional]

Here is the result, an empty page:
hidden link

while if I used the post title directly, th e correct posts (2 posts) show. so the view itself works:

hidden link

can you please help me identifying why my codes don't work?

thanks in advance