$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp query - Displaying Pages in Nav Sub-Menu with Specific Taxonomy Terms?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp query - Displaying Pages in Nav Sub-Menu with Specific Taxonomy Terms?

matteradmin8PV0评论

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.

Share Improve this question asked Aug 18, 2018 at 4:18 OpensaurusRexOpensaurusRex 16312 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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.

Post a comment

comment list (0)

  1. No comments so far