I have setup a post Type "Products" with different Categories (Video, Book, ....) and also different field Groups for al Categories.
How can I have the single product page use a different Content-Template?
When creating a ContentTemplate I can only select the Post Type but not a catergory that should use the Template, which means all Categories show in the same Template.
How can I use different templates for different categories?
Thanks
Gregor
I now tried to go a different rout and created different Post Types for the Categories:
Post Type 1: Videos
Post Type 2: Books
Post Type 3: XYZ
This gives me the option to have different Content Templates for each CType -which is what I need- but now I have a different Problem:
I try to set up a search on the home page to filter the results but I can not filter by Post Type as it seams 🙁
On a clients website that I made a few years ago (real estate) I used this code and it worked but I can't get it to work on this site:
[wpv-control url_param="wpv-post-type" type="select" values=",video,buch,zitatkarte" display_values="All Types,Video,Buch,Zitatkarte"]
Changing the select does not filter the search results that are shown.
Another problem with this 2. solution: I have set up different categories for each post type and It would be nict to be able to change the category select after changing the PT but this won't be possible either using the CPT solution I believe.
Which is the best was to proceed?
Hi first, I would like to show you how to apply different Content Templates to the same post type. We have a filter called wpv_filter_force_template that will programmatically override the template on-the-fly:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template
You can click the +More button to see an example of how to show a different template based on some conditional code. You can use wp_get_object_terms to inspect the terms currently associated with the post: https://codex.wordpress.org/Function_Reference/wp_get_object_terms
Let me know if you need more information about this approach, since it might be cleaner than new post types.
Second, filtering by post type isn't officially supported. This shortcode won't work by itself, it requires another PHP filter called wpv_filter_query: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
[wpv-control url_param="wpv-post-type" type="select" values=",video,buch,zitatkarte" display_values="All Types,Video,Buch,Zitatkarte"]
Check the site's custom PHP code, and you should find a corresponding PHP filter using wpv_filter_query. If not, you can use this post as a reference: https://toolset.com/forums/topic/post-type-filter/#post-486216
Note that this approach may not work with AJAX.
Hello Christian, thanks for your kind help!!
I found the extra function that I was using in the real estate site and now the search by Type works!
Another question:
in the search results I would like to show/print the PostType Name with every result to make clear it is a book or video.
PostType, Titel, .....
Is there any function available to get the CPT-Name of the listing?
Thanks
Gregor
There's a shortcode you can use wpv-post-type. The documentation for that and other Views shortcodes is available here: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-type
If you have other questions about that, feel free to open a new ticket. Thanks!
Thank you Christian, this was very helpful.
I managed to have it all working as expected!
Best Regards
Gregor