Hello im using this code in the admin to filter custom post types edit.php page
but get_current_screen $screen->post_type
is throwing a php notice.
Notice: Trying to get property of non-object
add_action( 'parse_query', 'filtering_edit_table' );
function filtering_edit_table( $query ) {
$screen = get_current_screen();
if( is_admin() && $screen->post_type == 'custom_post_type' && $screen->base == 'edit' ) {
// Do some things
}
}
How can I fix this?
Edit:
I am already requiring screen.php which contains get_current_screen()
require_once(ABSPATH . 'wp-admin/includes/screen.php');
Hello im using this code in the admin to filter custom post types edit.php page
but get_current_screen $screen->post_type
is throwing a php notice.
Notice: Trying to get property of non-object
add_action( 'parse_query', 'filtering_edit_table' );
function filtering_edit_table( $query ) {
$screen = get_current_screen();
if( is_admin() && $screen->post_type == 'custom_post_type' && $screen->base == 'edit' ) {
// Do some things
}
}
How can I fix this?
Edit:
I am already requiring screen.php which contains get_current_screen()
require_once(ABSPATH . 'wp-admin/includes/screen.php');
I tested this code and it worked fine. Where are you require
ing screen.php
? Same way as this?
require_once(ABSPATH . 'wp-admin/includes/screen.php');
add_action( 'parse_query', 'filtering_edit_table' );
function filtering_edit_table( $query ) {
$screen = get_current_screen();
if( is_admin() && $screen->post_type == 'custom_post_type' && $screen->base == 'edit' ) {
print_r($screen);
}
}