1

What actions run on the edit page in the admin section of a post type?

i.e. xyz.com/wp-admin/edit.php or xyz.com/wp-admin/edit.php?post_type=shop_order (custom post type)

I need to run a function when the page loads, after the query has performed to get all of the posts that will be displayed on the edit page.

What action should I use for this?

Thanks!

4

What actions run on the edit page in the admin section of a post type

Here are the do_action and do_action_ref_array calls, for the edit.php (post) screen, without any plugins and with a default theme activated:

muplugins_loaded - do_action
registered_taxonomy - do_action
registered_taxonomy - do_action
registered_taxonomy - do_action
registered_taxonomy - do_action
registered_taxonomy - do_action
registered_post_type - do_action
registered_post_type - do_action
registered_post_type - do_action
registered_post_type - do_action
registered_post_type - do_action
plugins_loaded - do_action
sanitize_comment_cookies - do_action
setup_theme - do_action
unload_textdomain - do_action
load_textdomain - do_action
load_textdomain - do_action
after_setup_theme - do_action
load_textdomain - do_action
load_textdomain - do_action
auth_cookie_valid - do_action
set_current_user - do_action
init - do_action
registered_post_type - do_action
registered_post_type - do_action
registered_post_type - do_action
registered_post_type - do_action
registered_post_type - do_action
registered_taxonomy - do_action
registered_taxonomy - do_action
registered_taxonomy - do_action
registered_taxonomy - do_action
registered_taxonomy - do_action
widgets_init - do_action
register_sidebar - do_action
register_sidebar - do_action
register_sidebar - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_register_sidebar_widget - do_action
wp_loaded - do_action
auth_cookie_valid - do_action
auth_redirect - do_action
wp_default_scripts - do_action_ref_array
_admin_menu - do_action
admin_menu - do_action
admin_init - do_action
wp_default_styles - do_action_ref_array
admin_bar_init - do_action
add_admin_bar_menus - do_action
current_screen - do_action
load-edit.php - do_action
parse_request - do_action_ref_array
send_headers - do_action_ref_array
parse_tax_query - do_action
parse_query - do_action_ref_array
pre_get_posts - do_action_ref_array
parse_tax_query - do_action
posts_selection - do_action
wp - do_action_ref_array
admin_xml_ns - do_action
admin_xml_ns - do_action
admin_enqueue_scripts - do_action
admin_print_styles-edit.php - do_action
admin_print_styles - do_action
admin_print_scripts-edit.php - do_action
admin_print_scripts - do_action
wp_print_scripts - do_action
admin_head-edit.php - do_action
admin_head - do_action
adminmenu - do_action
in_admin_header - do_action
admin_bar_menu - do_action_ref_array
wp_before_admin_bar_render - do_action
wp_after_admin_bar_render - do_action
admin_notices - do_action
all_admin_notices - do_action
restrict_manage_posts - do_action
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
the_post - do_action_ref_array
pre_get_users - do_action
pre_user_query - do_action_ref_array
pre_get_users - do_action
pre_user_query - do_action_ref_array
in_admin_footer - do_action
admin_footer - do_action
admin_print_footer_scripts - do_action
admin_footer-edit.php - do_action
shutdown - do_action

If we include the filters and even if we exclude the gettext filter, we get over five thousand lines!!. I posted it here on Github instead ;-)

I need to run a function when the page loads, after the query has performed to get all of the posts that will be displayed on the edit page.

I'm not sure what kind of function you need to run, but hopefully you can find your hook with these lists.

You could try for example the wp hook, that's fired later then the main WP_Query query:

Thanks to @TheDeadMedic for reminding me to target the edit.php screen for the shop_order ;-)

Here's the updated code snippet:

is_admin() && add_action( 'wp', function( \WP $wp )
{
    if( 'edit-shop_order' === get_current_screen()->id )
    {
        // ... your code here
    }
} );

I added the is_admin() check, since the wphook also fires on the front-end.

You can also check my answer here for other methods:

How to check if I'm on a custom post type archive in the admin area

  • 2
    I would suggest load-edit.php, the clue is in the name: load-{name-of-current-page} – TheDeadMedic Oct 3 '15 at 10:19
  • If I understand OP correctly, he was looking for an action that fires after the posts have been fetched from the database, for the main query. The load-edit.php action fires before that. But load-edit.php could be a hook wrapper to target the edit.php page. @TheDeadMedic – birgire Oct 3 '15 at 11:01
  • Yep, use a function hooked to load-edit.php that then attaches all the "real" hooks needed for the request. – TheDeadMedic Oct 3 '15 at 11:02
  • doh, I absolutely agree with you, using it as a wrapper, I thought I had used it here or the screen id, but I forgot to target the edit.php screen, sorry my mind was at another place and another question ;-) thanks @TheDeadMedic – birgire Oct 3 '15 at 11:04
  • 1
    Works like a champ @birgire thank you! (and thank you TheDeadMedic for the suggestion to improve performance by restricting it's running) – W00tW00t111 Oct 6 '15 at 18:56

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.