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
1 Answer
Reset to default 1If 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
评论列表(0条)