Adding Multiple Post Types to Query

This question already has answers here:Query multiple custom post types in single loop(2 answers)Closed 5 years ago.I�

This question already has answers here: Query multiple custom post types in single loop (2 answers) Closed 5 years ago.

I'm trying to add a 'Lessons' post type to populate the wp-query as well as the pre-existing post type 'Modules. Preferably I would like them to be combined into one query showing the most recent 6 posts. I've only been able to get them showing in 2 different queries thus far.

<?php 
//Template Name: Last 6 Modules
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'ca_show_last_six_modules' );
function ca_show_last_six_modules(){ 
$modules = new WP_Query(array(
    'post_type'         => 'module',
   'orderby'            => 'menu_order', 
    'order'                 => 'ASC',
    'status'            => 'publish',
    'posts_per_page'    => 6

));
if ( $modules->have_posts() ) : ?>
    <div class="row">   
        <?php while ( $modules->have_posts() ) : $modules->the_post(); ?>
            <?php get_template_part( 'template-parts/modules', 'loop' ); ?>
        <?php endwhile; ?>
    </div>
<?php endif;
}
 genesis(); ?>
This question already has answers here: Query multiple custom post types in single loop (2 answers) Closed 5 years ago.

I'm trying to add a 'Lessons' post type to populate the wp-query as well as the pre-existing post type 'Modules. Preferably I would like them to be combined into one query showing the most recent 6 posts. I've only been able to get them showing in 2 different queries thus far.

<?php 
//Template Name: Last 6 Modules
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'ca_show_last_six_modules' );
function ca_show_last_six_modules(){ 
$modules = new WP_Query(array(
    'post_type'         => 'module',
   'orderby'            => 'menu_order', 
    'order'                 => 'ASC',
    'status'            => 'publish',
    'posts_per_page'    => 6

));
if ( $modules->have_posts() ) : ?>
    <div class="row">   
        <?php while ( $modules->have_posts() ) : $modules->the_post(); ?>
            <?php get_template_part( 'template-parts/modules', 'loop' ); ?>
        <?php endwhile; ?>
    </div>
<?php endif;
}
 genesis(); ?>
Share Improve this question edited May 16, 2019 at 19:16 fuxia 107k39 gold badges255 silver badges459 bronze badges asked May 16, 2019 at 18:59 TylerTyler 11 bronze badge 0
Add a comment  | 

1 Answer 1

Reset to default 1

If you look at the wp_query documentation you will see that it is possible to pass multiple arguments as post_type. Like this:

'post_type' => array( 'module', 'lessons' )

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745486891a4629807.html

相关推荐

  • Adding Multiple Post Types to Query

    This question already has answers here:Query multiple custom post types in single loop(2 answers)Closed 5 years ago.I�

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信