Search code examples
phploopswhile-loopcustom-post-type

Multiple Custom Post Types Blog Page


I have a custom_post_type called promotions that I am trying to display correctly in index.php alongside the blog page. When I go to website.com/promotions it displays all of the current promotions. However, when I go to website.com/blog it states nothing found twice. (Currently there are 2 blogs on the site). The queries for each post-type and loop are stored within their corresponding template-parts files.

I know I'm probably missing something silly, but I am not sure what I am doing wrong and would appreciate the help. Example code below:

<?PHP 
if ( have_posts() ) :       
     if ( is_home() && ! is_front_page() ) :
     endif; 
     if ( get_post_type( get_the_ID() ) == 'post' ) : ?>
          ...HTML...<?PHP 
          while ( have_posts() ) :
               the_post();
               get_template_part( 'template-parts/content', 'none' );
          endwhile;
          the_posts_navigation(); ?>
          ...HTML...<?PHP
     endif; ?>
     ...HTML...<?PHP
     if ( get_post_type( get_the_ID() ) == 'promotions' ) : ?>
          ...HTML...<?PHP
          while ( have_posts() ) :
               the_post();
               get_template_part( 'template-parts/content', get_post_type() );
          endwhile;
          the_posts_navigation(); ?>
          ...HTML...<?PHP
     endif;
endif;
     

Solution

  • Figured it out, I knew it was something stupidly simple. Changing

    get_template_part( 'template-parts/content', 'none' );

    in post_type POST loop to

    get_template_part( 'template-parts/content', get_post_type() );

    fixed the problem with it not displaying correctly.