admin管理员组文章数量:1130349
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.
1 Answer
Reset to default 0I 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.
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.
1 Answer
Reset to default 0I 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.
本文标签: wp queryDisplaying Pages in Nav SubMenu with Specific Taxonomy Terms
版权声明:本文标题:wp query - Displaying Pages in Nav Sub-Menu with Specific Taxonomy Terms? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749048206a2308198.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论