I find the way, but it doesn”t work for my case because the plugin uses another function to link to parent pages, without using get_pages()
so the result is so inconsistent. But the filter is working.
// 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');
}
Feel free to comment.