Skip Navigation

[Resolved] Passing data to a view in order to dynamically create a url

This support ticket is created 2 years, 2 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by thomasB-12 2 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2502499

I have a post type Leadership. A Leadership can be categorized according to a custom taxonomy as one of the following types: Faculty, Board-Member, or PA.
I want the user to be able to go to a page with the following links:
Faculty
Board
PA
Each links to a page that displays the related post type Years. The post type Years is related to the post type Leadership. A Leadership can be attached to more than one Years.
I want to be able to click on the Faculty, Board, or PA link, and then be taken to the next page showing Years. Then I want to be able to click on a year and then be taken to a view that filters Leadership by Years AND by the custom taxonomy.
I’ve succeeded in filtering the Leadership according to their related Years. I did this by creating the following link from the Years view:
[wpv-post-title]
I then went on to filter Leadership according to their custom taxonomy by manually creating a link like this:
hidden link;?in-category=ap
The above link will show Leadership in a relationship posts with an ID 212 AND categorized as “ap”. So I know I can filter by post id AND category.
However I can’t figure out how to dynamically build the link with the category slug. It seems like it would have to be passed from the initial view, to the years view, and finally passed to the Leadership view.
I’ve been trying to figure this out but can’t seem to find anything in the documentation.
Can you help? Thank you.

#2503145

Hi,

Thank you for contacting us and I'd be happy to assist.

To achieve this, you can follow these steps:

1. You'll need these 3 pages:
- Select Category
- Select Year
- Filtered Results

Note: I'm using these names just for explanation and you're welcome to change them as needed.

2. On the first page "Select Category", you'll have a taxonomy view "View to show category selection links", which will show the list of all the terms from the category taxonomy.

Note: A taxonomy view can only be created using the classic/legacy view's editor.

In the loop of this view, you can create a link that takes you to the second page 'Select Year', along with the slug of the selected category term passed in the 'term' URL parameter, like this:


<a href="[wpv-post-url item='123']?term=[wpv-taxonomy-slug]">[wpv-taxonomy-title]</a>

Note: You'll replace '123' with the actual page ID of the 'Select Year' page.

3. On the second page 'Select Year', you'll have a post view "View to show year selection links", which will show the list of all the posts in the "Years" post type.

In the loop of this view, you can create a link that takes you to the third and final page 'Filtered Results'. This link will need to have the slug of the selected category term passed in the 'term' URL parameter (coming from the previous page) and the ID of the selected year post, in the URL parameter 'year', like this:


<a href="[wpv-post-url item='456']?term=[wpv-search-term param='term']&year=[wpv-post-id]">[wpv-post-title]</a>

Note: You'll replace '456' with the actual page ID of the 'Filtered Results' page.

Please also note, how I've used the "wpv-search-term" shortcode to get/reuse the already set URL parameter 'term' value:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-search-term

4. On the 'Filtered Results' page, you'll have a post view "View to show Leadership posts filtered by category and year" that will be set to show the "Leadership" posts.

At this point, you'll have the category slug as well as the year post ID, in the respective URL parameters and you can add query filters in this view to filter the results accordingly.

I hope this helps and please let me know if you need any further assistance with this.

regards,
Waqar

#2503457

My issue is resolved now. On the filtered results page I set the filter to Filter by post relationship or repeatable fields group owner, as related items of The post with ID set by the URL parameter, and the set the parameter to inyears, as years is reserved by WordPress.

I appreciate you help!