可以使用pre_get_posts
.
在所有变量名前加前缀很重要,id
似乎不在reserved terms list, 但无论如何,这种做法避免了任何不可预见的错误。
/**
* Usage:
* http://example.com/wp-admin/edit.php?my_pids=4088,4090,4092,4094
*/
add_filter( \'pre_get_posts\', \'limit_post_list_wpse_96418\' );
function limit_post_list_wpse_96418( $query )
{
// Don\'t run on frontend
if( !is_admin() )
return $query;
global $pagenow;
// Restrict to Edit page
if( \'edit.php\' !== $pagenow )
return $query;
// Check for our filter
if( !isset( $_GET[\'my_pids\'] ) )
return $query;
// Finally, filter
$limit_posts = explode( \',\', $_GET[\'my_pids\'] ); // Convert comma delimited to array
$query->set( \'post__in\', $limit_posts );
return $query;
}