• So I’ve got the following custom plugin which works like a charm for “pages”.

    But how can I modify it to also work with “posts”?

    The idea is that I want the default view of the “pages” dashboard screen & “posts” dashboard screen to show the “Published” not “All”.

    TIA

    function wcs_change_admin_page_link() {
        global $submenu;
        $submenu['edit.php?post_type=page'][5][2] = 'edit.php?post_type=page&post_status=publish';
    }
    add_action( 'admin_menu', 'wcs_change_admin_page_link' 
    );

    BONUS points if you can show me how to extend it to work for custom post types like:

    edit.php?post_type=fl-theme-layout
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    post_type and post_status query vars work for any edit.php request, just supply the appropriate values in each case. Your question is really more about where to apply these query vars. Add var_dump( $submenu ); to see the entire submenu data array. The output may not be visible on admin pages, or it’ll be a jumbled mess. Look at the page’s source HTML view for a more structured view.

    Identify the correct menu item to learn the proper array keys to use. For posts it should be
    $submenu['edit.php'][5][2] = 'edit.php?post_status=publish';

    For a CPT it’s likely
    $submenu['edit.php?post_type=fl-theme-layout'][5][2] = 'edit.php?post_type=fl-theme-layout&post_status=publish';

    you ought to verify these for yourself by examining your $submenu’s var_dump. Bonus: by examining the $submenu array, you can see how you also could alter menu labels if you like. For example, instead of All Pages, it could read Published Pages instead. Have fun 🙂

Viewing 1 replies (of 1 total)

The topic ‘Show Published Pages AND Posts by Default’ is closed to new replies.