Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
You should never have to hack to core. What exactly are you trying to accomplish, editing 2 custom post types at the same time? –  Wyck Mar 24 '11 at 20:00
add comment

1 Answer

up vote 2 down vote accepted

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:

add_action( 'pre_get_posts', 'wpse12970_pre_get_posts' );
function wpse12970_pre_get_posts( &$wp_query )
{
    if ( is_admin() && array_key_exists( 'multi_post_type', $_GET ) ) {
        $wp_query->set( 'post_type', $_GET['multi_post_type'] );
        add_filter( 'the_posts', 'wpse12970_the_posts', 10, 2 );
    }
}

function wpse12970_the_posts( $posts, &$wp_query )
{
    $wp_query->set( 'post_type', $GLOBALS['post_type'] );
    return $posts;
}

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, like WP_Posts_List_Table but then for multiple post types. Because edit.php loads this table by default and I see no way to intercept it, you should create your own replacement of edit.php in your plugin and use that. I think it is doable, and probably interesting, but a lot of work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.