你必须使用pre_get_posts
钩子以更改WordPress主查询。
$query->get()
: https://developer.wordpress.org/reference/classes/wp_query/get/
is_admin()
: https://codex.wordpress.org/Function_Reference/is_admin
pre_get_posts
挂钩:https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
// Handle the main query and set the post ID to 9
function wpse_288586_hide_products($query) {
// We have to check if we are in admin and check if current query is the main query and check if you are looking for product post type
if(is_admin() && $query->is_main_query() && $query->get(\'post_type\') == "product") {
$query->set(\'post__in\', array(9));
}
}
add_action(\'pre_get_posts\', \'wpse_288586_hide_products\');