我找到了方法,但它不适用于我的情况,因为插件使用另一个函数链接到父页面,而不使用get_pages()
所以结果很不一致。但过滤器正在工作。
// Get all posts with the meta key \'not_in_menu\'
function get_not_in_menu_posts() {
$post_ids = wp_cache_get( \'wl_not_in_menu\' );
if ( false === $post_ids ) {
$post_ids = array();
$args=array(
\'post_type\' => \'page\',
\'meta_key\' => \'not_in_menu\',
\'meta_value\' => \'1\'
);
$not_in_posts = get_posts( $args );
if( $not_in_posts ) {
$post_ids = wp_list_pluck( $not_in_posts, \'ID\' );
}
wp_cache_set( \'wl_not_in_menu\', $post_ids );
}
// return an array of IDs
return $post_ids;
}
function exclude_pseudo_page( $posts ) {
$excluded_posts = get_not_in_menu_posts();
$shaved_posts = array();
foreach ( $posts as $this_post ) {
if ( ! in_array( $this_post->ID, $excluded_posts ) ) {
$shaved_posts[] = $this_post;
}
}
return $shaved_posts;
}
if ( ! is_admin() ) {
add_filter(\'get_pages\', \'exclude_pseudo_page\');
}
请随时发表评论。