简体   繁体   English

Wordpress get_pages 基于页面类别

[英]Wordpress get_pages based on page category

I need to get_pages or get an array of pages in WP based on it 's category我需要 get_pages 或根据它的类别在 WP 中获取一组页面

I know WP doesn't come with categories on pages but I'm using this in the functions.php to get categories on the pages.我知道 WP 没有在页面上提供类别,但我在 functions.php 中使用它来获取页面上的类别。

    add_action('admin_init', 'reg_tax');

    function reg_tax() {
        register_taxonomy_for_object_type('category', 'page');
        add_post_type_support('page', 'category');
    }

Now I need to use these categories in get_pages or WP_Query to get in the pages with a category.现在我需要在 get_pages 或 WP_Query 中使用这些类别来获取具有类别的页面。

     <div class="productNav">

                <ul>

                <?php

                $product_page_args = array(

                    'post_type' => 'page',
                    'order' => 'ASC',
                    'orderby' => 'menu_order',
                    'child_of' => $post->ID,
                    'category_name' => 'pillar-product'
                );

                //$product_pages = get_pages($product_page_args);

                $product_pages = new WP_Query($product_page_args);



                foreach ($product_pages as $product_page){  

                ?>

                    <li><?php echo $product_page->post_title; ?></li>    

                <?php
                }
                ?>

                </ul>

            </div>

Try this:尝试这个:

$product_page_args = array(

                'post_type' => 'page',
                'order' => 'ASC',
                'orderby' => 'menu_order',
                'child_of' => $post->ID,
                'taxonomy' => 'category',
                        'field' => 'slug',
                        'term' => 'pillar-product'
            );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM