I am trying to see if there is a way to have the sub-menu items change depending the taxonomy of the of the page that is in the menu? I currently use the following WP_Query
I use to grab the top three items from the list of "Product Release" pages (these pages contain both release
and solutions
terms) associated with a "Solution" page and list them on the "Solution":
$my_terms = wp_get_post_terms(get_the_ID(), 'solutions', ['fields' => 'ids']);
$my_posts = new WP_Query(
[
'post_type' => 'page',
'posts_per_page' => 3,
'tax_query' => [
'relation' => 'AND',
[
'taxonomy' => 'solutions',
'field' => 'term_id',
'terms' => $my_terms
],
[
'taxonomy' => 'release',
'field' => 'term_id',
'terms' => get_terms('release', ['fields' => 'ids'])
]
],
'order' => 'DESC',
'orderby' => 'title',
]
);
However, I need to also be able to do something similar in the menu. Is there a way that pages in the menu, with only a solutions
term set, can have something like the above run on it to generate a submenu consisting of the top three pages that have both solutions
and release
terms?
The theme I am using is a modified twentyseventeen
theme and the nav menu is the core functionality included with twentyseventeen
.
I am trying to see if there is a way to have the sub-menu items change depending the taxonomy of the of the page that is in the menu? I currently use the following WP_Query
I use to grab the top three items from the list of "Product Release" pages (these pages contain both release
and solutions
terms) associated with a "Solution" page and list them on the "Solution":
$my_terms = wp_get_post_terms(get_the_ID(), 'solutions', ['fields' => 'ids']);
$my_posts = new WP_Query(
[
'post_type' => 'page',
'posts_per_page' => 3,
'tax_query' => [
'relation' => 'AND',
[
'taxonomy' => 'solutions',
'field' => 'term_id',
'terms' => $my_terms
],
[
'taxonomy' => 'release',
'field' => 'term_id',
'terms' => get_terms('release', ['fields' => 'ids'])
]
],
'order' => 'DESC',
'orderby' => 'title',
]
);
However, I need to also be able to do something similar in the menu. Is there a way that pages in the menu, with only a solutions
term set, can have something like the above run on it to generate a submenu consisting of the top three pages that have both solutions
and release
terms?
The theme I am using is a modified twentyseventeen
theme and the nav menu is the core functionality included with twentyseventeen
.
I was able to find a solution by creating a class that adds a filter that runs a meta query and an extra checkbox to the menu editor for the root items that need to be generated.