以下是三种可能性,基于/wp-admin/admin.php 文件:
方法#1有全局$pagenow 和$typenow 可用:
global $pagenow, $typenow;
if( \'my_venue\' === $typenow && \'edit.php\' === $pagenow )
{
// ...
}
然后是当前屏幕,也在
admin.php 使用文件
set_current_screen();
$screen = get_current_screen();
if( is_a( $screen, \'\\WP_Screen\') && \'edit-myvenue\' === $screen->id );
{
// ...
}
我们使用
id 的属性
\\WP_Screen 对象
如果我们浏览一下\\WP_Screen 同学们,我们发现current_screen 钩子,可以改用:
add_action( \'current_screen\', function( \\WP_Screen $s )
{
if( \'edit-myvenue\' === $s->id )
{
// ...
}
} );
方法3然后是
load-edit.php 钩子,在
pre_get_posts 挂钩:
add_action( \'load-edit.php\', function()
{
// Check for the post type here.
} );
在这种情况下,通用挂钩是
load-$pagenow. 不需要
is_admin() 在这里检查。
注意,如果您以主查询为目标,则应添加$query->is_main_query() 在您的pre_get_posts 回调。
还要记住验证$_GET[\'my_venue_ids\'] 部分,它甚至可能不存在于$_GET 大堆
这里没什么新鲜事!我想我们都见过这些方法,以这样或那样的方式,在许多问题中使用;WPSE上的答案;-)