I’m planing a custom post type functionality for my theme and need to be able to display more than just one post_type
in a admin overview table. That request I imagine might look like edit.php?post_type[]=theme_slide_nivo&post_type[]=theme_slide_other
. Haven’t actually tried that but i’m pretty confident it won’t work. So guys, is it possible to achieve such result without hacking core?
Leave a Reply
You must be logged in to post a comment.
I tried it out to get an idea of the problems you will run into. The following code allows you to specify multiple post types with the
multi_post_type
parameter:The first problem was that the global
$post_type
should be a single type, otherwise other functions break. So we “smuggle” the multiple post types in under another name, and remove them again after the query ran.The counter at the top of the list and the custom columns are based on only one post type. If there are many results paging will probably break.
If you want to do this, you should create your own list class, a child of
WP_List_Table
, likeWP_Posts_List_Table
but then for multiple post types. Becauseedit.php
loads this table by default and I see no way to intercept it, you should create your own replacement ofedit.php
in your plugin and use that. I think it is doable, and probably interesting, but a lot of work.Just picking up the comment above and let you know that I was able to use that code to filter multiple post types with it, simply replace:
$wp_query->set( 'post_type', $_GET['multi_post_type'] );
with
$wp_query->set( 'post_type', explode(',',$_GET['multi_post_type']) );
Simply use the URL with a comma-separated string like
&multi_post_type=page,post