Skip Navigation

[Resolved] Question about URLs and masking query strings

This support ticket is created 5 years, 12 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 Jackie 5 years, 12 months ago.

Assisted by: Waqar.

Author
Posts
#1200670

Hi Nigel,

This question, admittedly, is not about Toolset. It's a general question about WordPress, and as such you may not be able to help. The only reason I'm asking the question of Toolset support at all is because I'm organizing the content (custom post types, custom fields, taxonomy, etc.) for my site based on our discussions. I've hit a roadblock following that path and I'm hoping perhaps you can offer a pointer!

To refresh your memory, here is how I'm organizing my site's content: https://toolset.com/forums/topic/general-advice-on-building-a-college-course-catalog/.

+ On my catalog page, I'm displaying a list of departments. The URL looks like so:
hidden link

+ When I click on a department, it displays a list of courses in the department. The URL is like so:
hidden link

(Yes, both pages are using the same custom post type named "Catalog." I can't use the built-in archive because I need an archive of a given department in a given catalog, not just in a given department.)

What I would like to do is structure the department URLs like this:

hidden link

I Googled around and spent 2 hours looking at two possible solutions: Apache mod_rewrite and WordPress' built-in functions add_rewrite_tag() and add_rewrite_rule(). The closest I came was configuring mod_rewrite to translate this:

hidden link

to this:

hidden link

My page functions correctly, but the URL is ugly. I don't want visible query strings.

On a related note, I find that I'm using a single post type, "Catalog," to display both the list of departments and the list of courses in a department, and I'm manually coding this portion in a PHP theme file. Is there a way to connect the templates back to Toolset so I can use the graphical tools instead?

Please let me know if you have any questions. I'm curious about your thoughts.

Saul

#1200908

Hi Saul,

Thank you for contacting us.

Nigel will be away until Tuesday, but until then I'll be happy to assist you with your question.

Your understanding is correct and the first part of your message is related to how permalinks are handled in general by WordPress (and not Toolset plugins specifically). But we do our best to guide in the right direction, whenever possible.

As you noted, the functions "add_rewrite_rule" ( https://codex.wordpress.org/Rewrite_API/add_rewrite_rule ) and "add_rewrite_tag" ( https://codex.wordpress.org/Rewrite_API/add_rewrite_tag ) togather should let you convert, this:

/catalog/spring_2019/?department=painting

Into:

/catalog/spring_2019/painting/

You'll find the examples and suggestions in the following resources, very relevant:

hidden link
https://wordpress.stackexchange.com/questions/241325/change-query-string-to-pretty-permalink

For more detailed assistance and suggestions around WordPress' rewrite rules, you can post your question at the dedicated forums like:

https://wordpress.org/support/forums/
https://wordpress.stackexchange.com/

Moving on to the second part of your message, if the link "/catalog/spring_2019/?department=painting" is working, I'll assume that you already have a Toolset View or custom PHP template in place, which gets the value of the URL parameter "department" and treats it as a taxonomy term slug for the custom taxonomy "department".

After you've achieved the desired URL structure ( i.e. /catalog/spring_2019/painting/ ), you'll be able to retrieve the value "painting", by using the "get_query_var" function:
https://codex.wordpress.org/Function_Reference/get_query_var

>> Is there a way to connect the templates back to Toolset so I can use the graphical tools instead?

- The Toolset's content template can be assigned to single post type pages.
https://toolset.com/documentation/getting-started-with-toolset/create-templates-to-display-custom-posts/

But in your case, the list of departments and the list of courses in a department both are not a single post type.

To show them, you can assign a one content template to your single catalog page, which is indeed a custom post, and further create additional child content templates to show information about departments and courses.

It is possible to include or nest multiple content templates, within a main post content template, by using the "wpv-post-body" shortcode:
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153372

Tip: you can also create a custom shortcode, that checks that whether only catalog page is being viewed ( e.g. hidden link ) or if its a department list page ( e.g. hidden link ) based on the value of "get_query_var".

That custom shortcode can then be used with condtional code blocks, to show/hide nested content template(s) accordingly:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

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

regards,
Waqar

#1201484

Waqar,

The first link to the WPMUDev site was excellent and helped me to create URLs with an arbitrary structure. Thanks!

Regarding using the Content Templates, I love the purity of that solution. I've replaced a chunk of PHP using this approach. I'm still having some trouble making it all work, but I'll open new support tickets as needed.

Thanks!

Saul