3

I have successfully created a custom post type. I'm trying to construct a URL which points to a combined listing of posts of all post types on the view all posts page in the admin view.

I can construct a URL which points to posts of specific post types, eg http://<mysite>//wp-admin/edit.php?post_type=my_post_type. But I can't find a way of listing posts of all post types.

Is it possible to use the /wp-admin/edit.php?post_type= slug to point to a page listing posts of all post types? Or, how else can I build a URL which will?

  • Are you saying you want a page that lists all of the different post type entries? Or a page that lists all the posts from a specific post type? – Fencer04 Aug 29 '16 at 21:00
  • A page that lists all of the different post type entries – HamJam Aug 29 '16 at 21:01
  • You're trying to achieve this on the admin side of things, correct? Where the admin can edit every post of every post type in one place? – Howdy_McGee Aug 29 '16 at 21:03
  • Yes, this would be a listing in the admin side. The only thing my custom post type does differently from the normal post type is it injects some text into $content. I don't need to separate the different post types. It is better that the editor managing the posts can see all the posts in one listing. – HamJam Aug 29 '16 at 21:05
  • codex.wordpress.org/Function_Reference/… - you'll need your own page to construct the table, but with the post types you could run a query for all of that type. – jgraup Aug 29 '16 at 21:27
4

The only way this could work would be ?post_type=any based on WP_Query post_type params.

But the context is the problem, the edit.php page requires a specific post type, to display and edit only one $post_type_object which returns, for each post_type, only one singular label, one plural label and so many others individual properties.

These are not only technical blocking problems but also conceptual ones which make this impossible to be done.

Personally, I would research on "How to build a custom admin page" with a query like post_type=any

  • Just been arriving at a similiar conclusion. Actually found a duplicate of this question from 5 years ago here: wordpress.stackexchange.com/questions/12970/…. Same issues then. – HamJam Aug 29 '16 at 21:50
  • yep, that is similar, I couldn't find it tho – Andrei Aug 29 '16 at 22:01
  • Sorry I can't upvote your answer, I don't have enough rep (2 to go!). But thanks for your help – HamJam Aug 29 '16 at 22:10
  • Don't worry, I'm glad I could help – Andrei Aug 29 '16 at 22:11
1

You could use pre_get_posts with a $_GET parameter and piggyback on the current post type - for example, say we're viewing all editable posts in the admin panel, we can add a parameter showall=true and show all post types:

/**
 * Show all post editable post types
 *
 * @param WP_Query Object $query
 *
 * @return void
 */
function show_all_posttypes( $query ) {
    if( ! is_admin() ) {
        return;
    }

    if( isset( $_GET, $_GET['showall'] ) && true == $_GET['showall'] ) {
        $query->set( 'post_type', 'any' );
    }
}
add_filter( 'pre_get_posts', 'show_all_posttypes' );

If you want to limit the post types by some way or another you can use get_post_types() function and pass the returned post types into the post_type parameter as an array().

We can even add this as a subpage admin link for ease of access:

/**
 * Show All Post Types Link
 * - Subpage of "All Pages"
 *
 * @return void
 */
function show_all_posttypes_link() {
    add_submenu_page('edit.php?post_type=page', '', 'All Post Types', 'edit_posts', '/edit.php?post_type=page&showall=true');
}
add_action( 'admin_menu', 'show_all_posttypes_link' );

You could keep extending this on and on to customize the column outputs and such but this is the gist of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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