The function you are looking for is get_current_screen()
. To check if you are on a specific custom post type page, do as follows:
$screen = get_current_screen();
if ( $screen->post_type == 'custom_job' ) {
// We are on custom_job post type, good to go
}
Now, if you visit edit.php?post_type=custom_job
, this conditional will return true, which you can set your query inside.
There is also another approach for this. By using is_post_type_archive('custom_job')
, you can target the edit.php?post_type=custom_job
. Make sure you use this in conjunction with is_admin()
to make sure you don’t target the front-end.