I have a custom post type, and want to display the archive in two different ways, showing different fields of the archive
e.g.
Archive 1 grid:
Title/Link
Image
CPT Data field A
CPT Data field B
Archive 2 grid:
Title/Link
Image
CPT Data field C
CPT Data field D
Is this possible? Looks like I can only have one archive layout assigned to a CPT at a time, unless I'm missing something. My google-fu has let me down...
Thanks...
Dear Ivan,
Yes, it is expected result, but you can use Views filter hook "wpv_filter_force_wordpress_archive" to change it, see our document:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_wordpress_archive
Filters the ID of the WordPress Archive to be used on a given archive loop.
For example, this thread:
https://toolset.com/forums/topic/possible-to-have-multiple-templates-for-archives/#post-606155
Thanks. In my scenario, I'll be using a different archive if the post type is assigned a certain category. It looks like your example thread code is almost perfect for my use case, so thanks for the link! I'll leave the ticket open for now and will check in when I (hopefully) get it working to close the ticket.
I take it the hook can go in theme functions.php?
I'm missing something fundamental. I ended up cloning my main layout. I changed the copy by adding a query filter in the archive cell that shows only those cells where mytaxonomy=myvalue. If I assign the original layout to the archive, it shows all cells. If I assign the modified copy, it shows the filtered view I want. Now all I need is a way to display both layouts.
I'm not sure if I can do this with a url - everything I've read says I cant easily do domain.com/CPT/taxonomy/taxonomy-value format urls out of the box.
Maybe I can have urls
domain.com/CPT
and
domain.com/CPT?showalternatelayout=1 (or similar)
and use the GET variable in the wpv_filter_force_wordpress_archive hook to force the alternate layout?
I'm guessing there's a better solution? Thanks for sticking with me - I'm learning!
As you can see, it needs custom PHP codes, to avoid any misunderstanding, please elaborate the question with more details:
Now all I need is a way to display both layouts.
For example there are two WordPress Archive in your website:
- WordPress Archive A
- WordPress Archive B
Where (what page) and in what condition do you want to display the WordPress Archive A?
Where (what page) and in what condition do you want to display the WordPress Archive B?
Please describe detail steps to duplicate same problem, I need to test it in my localhost, thanks
Thanks for getting back to me.
I have custom post type student, with archive view showing grid of all students, I have taxonomy "student status" where some students are assigned "board member" category. I've successfully created the archive to show all students and the archive with query filter to show only students that are board members. By assigning one at a time to be the archive view, I've demonstrated that both work as I want them. I now need to be able to access them as two distinct locations from the menu - e.g. student menu item and board member menu item.
The only thing I can think of at the moment is a GET variable in the URL so
hidden link
shows the regular archive view
and
hidden link
shows the second archive view with the query filter. I would use functions.php to retrieve GET variable and if set, use wpv_filter_force_wordpress_archive to return the query filter archive id. This doesn't seem like the most elegant solution though.
Hope it makes sense?
Please try this:
add_filter( 'wpv_filter_force_wordpress_archive', 'board_members_archive_func', 99, 2 );
function board_members_archive_func( $wpa_assigned, $wpa_loop ) {
if ( isset($_GET['board-members']) && $_GET['board-members'] == 1) {
$wpa_assigned = 1234;
}
return $wpa_assigned;
}
replace 1234 with your second archive view's ID
Hi. No luck, I'm afraid. I've added debug logic to your code, and verified that the code is retrieving the GET variable correctly and setting/returning the layout ID of the query filtered layout (1390) that I got from Toolset Layouts ( wp-admin/admin.php?page=dd_layouts ). However the original layout is still used to show the archive.
Looking again at the docs and your reply, I see that maybe the hook in question acts on WordPress Archives, not layouts? I cloned the main view and put the same query filter on it, and set the id in the to the new WP Archive ID instead. Still no luck.
Since it is a custom PHP codes problem, please duplicate same problem in a test site, and fill below private detail box with login details and FTP access, also point out the problem archive page URL, and where I can edit you PHP codes, I need a live website to test and debug, thanks
Thanks for the details, I am checking it in your website, will feedback if there is anything found
There is a misunderstanding, the "wpv_filter_force_wordpress_archive" only works for the Views wordpress archive, but in your case, it needs to assign different layout, please try Layouts filter hook "get_layout_id_for_render", like this:
add_filter( 'get_layout_id_for_render', 'board_members_archive_func', 999, 2 );
function board_members_archive_func( $layout_id, $layout) {
if ( isset($_GET['board-members']) && $_GET['board-members'] == 1) {
$layout_id = 1390;
//print_r ("yes");
}
else {
//print_r ("no");
}
return $layout_id;
}
I appreciate your help and patience in helping me to resolve this matter.