doufei16736 2017-07-20 16:28
浏览 39

覆盖“博客页面最多显示”并显示自定义帖子类型的所有帖子

I'm trying to overwrite the default 'Blog pages show at most' which is set to 5 posts. I have a custom post type called 'FAQs', which has the argument 'posts_per_page' => 999 in the query for getting all the posts of this type, however I can't seem to override the default restriction in the WordPress setting. My code for the FAQ query is below, which works on my local machine (MAMP) but not when I upload it to live. how do I show all posts of that type?

                  <?php

                      wp_reset_query();

                      // Query for getting custom taxonomy 'FAQ Type' of custom post type 'FAQs'
                      $cat_args = array (
                        'taxonomy' => 'faq_type',
                        'exclude' => array(12),
                        'posts_per_page' => 999,
                        //'show_all' => true,
                        'orderby' => 'simple_page_ordering_is_sortable'
                      );
                      $categories = get_categories ( $cat_args );

                      foreach ( $categories as $category ) {

                        //wp_reset_query();

                        $cat_query = null;

                        // Query for getting posts of custom post type 'FAQs'
                        $args = array (
                          'post_type' => 'faq',
                          'faq_type' => $category->slug,
                          'posts_per_page' => 999,
                          //'show_all' => true,
                          'orderby' => 'simple_page_ordering_is_sortable',
                        );
                        $cat_query = new WP_Query( $args );

                        if ( $cat_query->have_posts() ) { ?>

                        <?php echo "<h2>". $category->name ."</h2>"; ?>

                        <ul id="resident-accordion" class="accordion white-bg-accordion" data-accordion data-allow-all-closed="true" role="tablist">

                        <?php

                          while ( $cat_query->have_posts() ) {
                            $cat_query->the_post();
                            ?>

                              <li class="accordion-item faq-content <?php //if ($firstLoop === true) { echo "is-active"; }?>" data-accordion-item>
                                <a href="#" class="accordion-title" role="tab"><?php the_title(); ?></a>

                                <div class="accordion-content" data-tab-content>
                                  <?php the_content(); ?>
                                </div>
                              </li>

                            <?php
                          } //wp_reset_query();
                          wp_reset_postdata(); //End WHILE

                        echo "</ul>";

                        } //End IF
                        wp_reset_postdata();
                        //wp_reset_query();
                      } //End FOR
                  ?>
  • 写回答

1条回答 默认 最新

  • dongshu7162 2017-07-21 04:01
    关注

    You can try to use this code below :

    <?php
    $cat_args = array(
        'taxonomy' => 'faq_type',
        'exclude'  => array(7),
        'orderby'  => 'simple_page_ordering_is_sortable'
    );
    
    $categories = get_terms( $cat_args );
    
    foreach ( $categories as $category ) 
    {
        $args = array(
            'post_type'      => 'faq',
            'posts_per_page' => -1, // load all posts
            'orderby'        => 'simple_page_ordering_is_sortable',
            'tax_query'      => array(
                array(
                    'taxonomy' => 'faq_type',
                    'field'    => 'slug',
                    'terms'    => $category->slug
                )
            )
        );
    
        $cat_query = new WP_Query( $args );
    
        // enter the rest of your code below
    }
    

    Or you can use get_posts() to receive posts list.

    <?php
    $cat_args = array(
        'taxonomy' => 'faq_type',
        'exclude'  => array(7),
        'orderby'  => 'simple_page_ordering_is_sortable'
    );
    
    $categories = get_terms( $cat_args );
    
    foreach ( $categories as $category ) 
    {
        $posts = get_posts(array(
            'numberposts'   => -1, // get all posts.
            'tax_query' => array(
                array(
                    'taxonomy' => 'faq_type',
                    'field'    => 'slug',
                    'terms'     => $category->slug,
                    'operator' => 'IN',
                ),
            ),
            'post_type'     => 'faq',
        ));
    
        // enter the rest of your code below
    }
    

    Cheers!

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制