I'm trying to build a three menu from a custom post type, and wanna build a complet three from the posts children and parents, with all levels both up and down included.
And actually the function wp_list_pages()
does that really great, and actually includes all levels that i want.
But i also want to modify the query a little, and exclude some post that fits within a meta query, that i'm using another place like this:
$meta_query[] = array(
'relation' => 'or',
array(
'key' => 'rank',
'compare' => '<=',
'type' => 'NUMERIC',
'value' => 100,
),
array(
'key' => 'rank',
'compare' => 'NOT EXISTS',
'value' => 1,
),
);
The only problem is that wp_list_pages()
don't support the meta_query, and only looking for at specific meta key and value.
Does anybody have a solution for this, or an idea to archive the goal?
I'm trying to build a three menu from a custom post type, and wanna build a complet three from the posts children and parents, with all levels both up and down included.
And actually the function wp_list_pages()
does that really great, and actually includes all levels that i want.
But i also want to modify the query a little, and exclude some post that fits within a meta query, that i'm using another place like this:
$meta_query[] = array(
'relation' => 'or',
array(
'key' => 'rank',
'compare' => '<=',
'type' => 'NUMERIC',
'value' => 100,
),
array(
'key' => 'rank',
'compare' => 'NOT EXISTS',
'value' => 1,
),
);
The only problem is that wp_list_pages()
don't support the meta_query, and only looking for at specific meta key and value.
Does anybody have a solution for this, or an idea to archive the goal?
Share Improve this question asked Nov 6, 2020 at 10:37 bymembymem 111 bronze badge1 Answer
Reset to default 0So i got it working, by adding a filter:
i added this before the wp_list_pages
add_filter( 'get_pages', 'check_propper_rank', 10, 2 );
wp_list_pages( array(
'post_type' => 'wiki-term',
) );
and then created a new filter, to removed the ones that did'nt fit the rank.
function check_propper_rank( $pages, $arguments ) {
$user_rank = 100;
foreach ( $pages as $key => $page ) {
$required_rank = get_post_meta($page->ID, 'rank', true);
if ( $required_rank >= $user_rank ) {
unset($pages[$key]);
}
}
if ( empty( $pages ) )
return $pages;
// Remove instantly
remove_filter( current_filter(), __FUNCTION__, 10 );
return $pages;
}