I'm building a guitar lessons site and I have a question about Custom Post Types. I am creating a "Lessons" page which will be my main blog / loop. I also wanted to create a custom post type for "Arrangements" which will be just video / songs I arrange and play.
I'm using CPT UI for the custom post type called "Arrangements" and I'm trying to figure out how to create separate loops - Lessons = main post type, Arrangements = custom post type.
I have a arrangements.php template that has a loop like so:
$args = array(
'post_type' => array('post', 'arrangements'),
'post_status' => 'publish',
);
$new_post_loop = new WP_Query($args);
if ($new_post_loop->have_posts()) :
while ($new_post_loop->have_posts()) :
$new_post_loop->the_post();
get_template_part('template-parts/content', 'blog');
endwhile;
the_posts_navigation();
else :
get_template_part('template-parts/content', 'none');
endif;
?>
However, it's pulling in all of my Lessons as well as the custom post type. Any idea of what I'm doing wrong? Thank you.
I'm building a guitar lessons site and I have a question about Custom Post Types. I am creating a "Lessons" page which will be my main blog / loop. I also wanted to create a custom post type for "Arrangements" which will be just video / songs I arrange and play.
I'm using CPT UI for the custom post type called "Arrangements" and I'm trying to figure out how to create separate loops - Lessons = main post type, Arrangements = custom post type.
I have a arrangements.php template that has a loop like so:
$args = array(
'post_type' => array('post', 'arrangements'),
'post_status' => 'publish',
);
$new_post_loop = new WP_Query($args);
if ($new_post_loop->have_posts()) :
while ($new_post_loop->have_posts()) :
$new_post_loop->the_post();
get_template_part('template-parts/content', 'blog');
endwhile;
the_posts_navigation();
else :
get_template_part('template-parts/content', 'none');
endif;
?>
However, it's pulling in all of my Lessons as well as the custom post type. Any idea of what I'm doing wrong? Thank you.
Share Improve this question asked Jan 8, 2021 at 13:25 sackadelicsackadelic 376 bronze badges 2 |1 Answer
Reset to default 1You don't specify this, but if your lessons
are being pulled in along with your arrangements
then you must be using default WordPress posts
for the Lessons... assuming that, here's what's happening in your code.
On the second line when you're setting your query arguments ($args
) you specify that you want BOTH the posts
post type and your custom arrangements
post type. So you get both.
Simple fix though, just use this for your $args
.
$args = array(
'post_type' => 'arrangements,
'post_status' => 'publish',
);
You could still leave it as an array though, no harm...
$args = array(
'post_type' => array('arrangements'),
'post_status' => 'publish',
);
Give that a try and see if you get the desired result.
posts
as "Lessons"? – Tony Djukic Commented Jan 8, 2021 at 15:33