Tell us what you are trying to do?
Organize courses into categories.
Categories have a hierarchy and a course belongs both to category and subcategory.
site.com/courses/category-name/
site.com/courses/category-name/sub-category/
and I also want to display a filtered view for "free courses" ideally automatically for each in this format
site.com/courses/category-name/free
site.com/courses/category-name/sub-category/free
Free is a custom field of a course. I know how to filter but I am not sure how I can have that /free taxonomy automatically created for all categories and sub-categories.
Not sure how to best choose between CPT and Taxonomy to structure this.
Is there any documentation that you are following?
No
Is there a similar example that we can see?
hidden link
Thank you.
Hello and thank you for contacting Toolset support.
From reading your initial message, I am keen to understand that you are looking to have this kind of permalink structures:
- site.com/courses/category-name/
- site.com/courses/category-name/sub-category/
- site.com/courses/category-name/free
- site.com/courses/category-name/sub-category/free
Right?
So, first of all, you must note that WordPress has default permalink structures that cannot be customized using Toolset. They may be customized using custom code, which is out of the scope of the support forum.
These are WordPress default permalink structures:
- site.com/cpt-slug/ : For the post type archive.
- site.com/cpt-slug/post-slug/ : For single posts.
- site.com/taxonomy-slug/term-slug/ : For taxonomies archives.
Read more about it in the following articles:
- https://wordpress.org/support/article/using-permalinks/#structure-tags
- https://wordpress.org/support/article/settings-permalinks-screen/
- hidden link
There are also 3rd party plugins that can help with the permalink structures, such as:
- https://wordpress.org/plugins/permalink-manager/
- https://wordpress.org/plugins/tags/permalinks/
Please note that we do not recommend any of them. Use them at your own risk.
Using a custom field in the permalink structure, will for sure need some custom code unless a 3rd party plugin offers it. Check the following threads:
- https://stackoverflow.com/questions/50537321/custom-permalink-structure-for-custom-post-type-based-on-meta-fields-and-custom
- hidden link
However, WordPress allows having some kind of nested permalinks, for hierarchical post types. Check my test site here hidden link
I created a Hierarchical custom post type "Courses". Check this screenshot hidden link
Then I created two custom posts, one as a parent, and the other as a child, check this screenshot hidden link
And that allowed me to have the following structure:
- For the parent post: hidden link
- For the child post: hidden link
I believe the above is important, so you can understand how the internals of WordPress, in terms of URLs work. After that, I am sure, you will have different questions. So, I'll remain at your disposal.
I hope this helps. Let me know if you have any questions.
This is helpful to make me understand even better the potential permalinks structure.
However, I believe I explained badly what I am trying to achieve. I don't need to change the WordPress structure at all and don't need hierarchy posts either.
The course is a custom post type and it has fields like title, description... and the category and sub-category can be fields or taxonomies for it.
The courses are grouped into categories and sub-categories and my question was if I should simply use taxonomy to display the list of courses as an archive or make the categories a separate custom post type, mainly so I can display a "/free" taxonomy for them.
I guess probably my biggest roadblock is how to add a /free taxonomy with a custom filtered view on the category archives if they are just taxonomies of the Course CPT and not their own CPT.
Thanks.
Well, that's up to you to decide if you want to go with taxonomy archives, or with regular pages using views.
Personally, I would go with taxonomies for the course categories, instead of a new CPT. But that depends on what we are looking to achieve.
You can use a taxonomy that has a free term. Or you can use a custom field. Then you can filter, either the archive or the view to display those courses.
This always goes down to what URL you would like to have. Because archives have special URLs. And archive templates can also be filtered(to get the free ones) using a different taxonomy or a custom field.
So, it goes down to what do you want to achieve. Maybe if you let me log in to your website and see what has been done, I'll better advise you.
I'll also need to know where do you want to display the free courses? In a separate page(what URL?)? or in a sidebar? Etc.
I actually think this is private messaging?
Given your end of day is soon I am including the login.
If somehow someone gets in it's under development so nothing really to brea.
[Credentials moved to private reply.]
I've added a few courses and a few taxonomy categories.
Feel free to edit as you want as the site is under development and also data will be re-imported so nothing to break. I've also taken a backup in case a restore is needed.
If you look at hidden link - it works perfectly
Now all I want is to have hidden link display a filtered view of the courses under Enterpreneursip.
If I manually create the slug WordPress wants them to be unique so need to duplicate like hidden link
I also want to display a link in the archive to the free selection of the courses.
Example from another site: hidden link - see the Free in the top menu that links to hidden link
I need this functionality both for SEO and usability.
From all my research this doesn't seem doable with taxonomy and maybe there is a need to hack it somehow via separate CPT and even intermediary?
Thank you.
Well, I believe that you will need custom code that will translate the last "/free" URL fragment to a filter. That way you can use the "free" keyword, either as a taxonomy term or as a custom field. And you can force the archive template to filter using it.
Check these articles, I am sure, they will give you more insights:
- hidden link
- hidden link
- hidden link
- https://developer.wordpress.org/reference/functions/add_rewrite_rule/
You can also use the pre_get_posts hook from WordPress to modify the archive query. But you will still need a rewrite rule to make sure that the desired URL (hidden link....../free) does not return a 404 page.
I hope this makes sense. Let me know if you have any further questions.
1. Can you please help me with the re-write code for my scenario?
All I need is that "free" filter.
I understand if it's out of support scope.
2. How do I link it from the regular archive page?
Thank you.
So I experimented for a few hours with both Taxonomy and having a separate CPT for categories.
As you suggested it makes a lot of sense to use the Taxonomy and will go with that.
There are 2 things remaining to take the project live and I hope you can help.
Please look at this example URL hidden link
1. I know how to add a grid. How do I add radio buttons or checkbox filtering elements to its left column?
2. Again, as you suggested how can I have a radio button (filter) to just load a custom URL - see the Mid Market filter on the left menu on the example URL. I will use this to filter Free courses and replicate the same to show Paid courses. From the example URL, the first selection in my case would be All, Free, Paid with All being the default.
I did check all the documentation you sent yesterday but I don't know how to edit PHP code.
The login details from the earlier ticket are still working if you can please just go in and set it up.
Thank you.
I am keen to help with the custom code for rewrite rules, but as it is out of scope, I can only do it when I have some spare time. First, I need to handle support requests that are within the scope, and when I got some time, I can work on this.
Regarding 1. The filter can only be added using the Toolset button(Add search) inside the search area. Then you can drag/drop it to the sidebar, or to cell inside the grid.
Regarding 2. That can be done using hard-coded links. Or using custom Javascript code that will listen to a change event on the filter, and according to the selected value, it can redirect the page:
window.location.href = new_link;
I'll be on my weekend on Wednesday and Thursday. So, I'll try to find time to experiment with the rewrite-rules starting from Friday.
Thank you for this.
Can you please set my next message to be a private message so I can drop the login details to the dev site for you to have access on Friday?
I will take the site live without it meanwhile.
Have a great mid-week weekend 🙂
Of course. Your next reply will be private.
So, I've simplified this a lot. The previously shared login still works if you want to log in.
I took your advice and used Permalinks Manager Pro (I understand it wasn't an endorsement).
I flatted with it all categories to the format: hidden link as that will allow workaround 1 below.
1. Now I could just set links to a "free" filtered page by using this View Only the Free [wpv-taxonomy-title] Courses.
Is this a good idea while setting up Free as a separate taxonomy with that custom URL structure and just duplicate all categories? Is there a more elegant way to do this?
There is a custom field called: is-course-paid that has values "free" or "paid". Would be great if I could just leverage that for the custom URL structure /free especially with the permalink plugin.
2. Is it possible to add an option that has them all? In the DB they are listed as either free or paid.
See example search/filter here hidden link
Thank you.
Sorry, but I did not understand this question 2. Is it possible to add an option that has them all? In the DB they are listed as either free or paid.
Honestly, I don't see a use case where would like to save both cases to the database.
However, according to this article, it is possible to amend a custom field to archive permalinks. Especially step2 "Add custom fields tags to WordPress permastructure settings"
hidden link
Personally, I would use a taxonomy that has two terms "Paid" and "Free". Primarily because taxonomy-based queries are faster than custom field-based queries. And the plugin seems to support this case (2 taxonomies in the permalink).
And it would also allow having a post that is both "Free" and "Paid", even though, I still don't see a use case for it.
I believe, if you use this plugin, it would be worth reading the developer articles. The ones under the "Filters & Hooks" section.
hidden link
Keep in mind that Toolset uses URL parameters for filtering. For example this URL will filter the archive to display only the Free courses hidden link
Especially the wpv-wpcf-course-is-paid%5B%5D=Free which is then translated to:
$_GET['wpv-wpcf-course-is-paid[]'] = 'Free';
We are almost there. I appreciate the patience.
Re, both free and paid, as in "all" I meant as a checkbox in the search filter that shows them all but that will not be needed if below is implemented.
So given my current setup what do I actually need to do to display at hidden link only the courses that have the category Entrepreneurship and the custom field Is Course Paid set to free?
I agree with the taxonomy being better to use.
You can also log in and set it if you don't mind.
I assume it's a combo setup between Toolset and Permalinks Manager Pro.
Thank you.
I logged into your website and I tried to append the custom field handler to the taxonomy permalink structure, but it did not work. So, I read the documentation article and it is not clear if this feature(custom field) is supported on taxonomy archives. The example there is for custom post-type archives.
So, I looked online, but I could not find a plugin that does this(combining two taxonomies, or custom field and taxonomy in the taxonomy permalink). However, I was able to find some online solutions using custom code.
- https://wordpress.stackexchange.com/questions/31738/how-do-i-append-multiple-taxonomies-to-the-url
- https://wordpress.stackexchange.com/questions/280497/archive-page-with-multiple-taxonomies-rewrite
I did not test any of these solutions yet, because I am pretty sure we'll encounter issues with the existing plugin. And I'd prefer to test it in my local development environment before trying on an online site.
I'll find the time to test it and get back. In the meantime, you can always try from your end using an additional taxonomy for (free/paid) posts.
Using a taxonomy, or a custom field(should be select or radio instead of single line), will allow us to generate automatically the "All" option in the search filter. So that's handled out of the box. When we get to it, I'll explain how to implement it.