0

Could anyone be kind enough to descrive how to I can detect (in my functions file) when admin an user is on the 'All Posts' page?

I have tried get_post_type() but it returns nothing.

Thanks.

  • What is All posts page ? A normal WordPress Page create through WP Admin -> Pages ? – Shazzad Dec 30 '13 at 22:57
  • The 'All Posts' page is shown below the 'Posts' page in the main admin sidebar. The URL for it on my setup is localhost/wptest/wp-admin/edit.php – ban-geoengineering Dec 30 '13 at 23:23
  • Ok, anwser provided – Shazzad Dec 31 '13 at 0:04
2

If you need exactly on All Posts page, Not on All Pages, nor All Products or etc -

if 
(
    'edit.php' === $GLOBALS['pagenow']
    && ( 
        isset( $GLOBALS['typenow'] ) 
        && '' == $GLOBALS['typenow'] 
        || 'post' == $GLOBALS['typenow'] 
    )
)
{
    // Do what you like...
}
0

If I understood you correctly, this is what you are looking for:

if (
    'edit.php' === $GLOBALS['pagenow']
    && ! isset($_GET['action'])
) {
    // Do what you like...
}
0

Take a look at get_current_screen():

function do_something_on_all_posts_page() {
    $screen = get_current_screen();
    if ( $screen['base'] == 'edit' && $screen['post_type'] == 'post' ) {
        /* Your code here */
    }
}
add_action( 'current_screen', 'do_something_on_all_posts_page' );
  • This answer doesn't check if the user is an admin - do you additionally need that criteria met in the answer, or were you only mentioning admin in reference to the page location (i.e. is_admin())? – Joshua Brian Davis Dec 31 '13 at 3:05
  • Thanks. This looks like a much nicer solution, but I need to use this code with the 'posts_join', 'posts_where' and 'posts_groupby' hooks. And when I use the get_current_screen() function from those hooks, I get a white screen in the front end. – ban-geoengineering Jan 1 '14 at 15:38

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.