1

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.

2
  • Are you using the default WordPress posts as "Lessons"? Jan 8, 2021 at 15:33
  • Yes - sorry for any confusion.
    – sackadelic
    Jan 8, 2021 at 19:02

1 Answer 1

1

You 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.

2
  • Thanks a lot! That fixed it.
    – sackadelic
    Jan 8, 2021 at 19:09
  • Glad to help. :-) Jan 8, 2021 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.