WordPress.org

Forums

[resolved] query posts from multiple post types (3 posts)

  1. artlover578
    Member
    Posted 9 months ago #

    Hello All,

    I was wondering if someone could help me, i would like to query the latest 5 post from my 3 custom post types and woocommerce. but i would like there to always be 5 posts all together at any given time. I would really appreciate the help.

    Thank you.

  2. artlover578
    Member
    Posted 9 months ago #

    If anyone was wondering i found the solution in another post on this forum

    Here it is :

    <?php query_posts( array(
         'post_type' => array( 'post-type', 'post-type', 'post-type', 'post-type' ),
         'cat' => 3,
         'showposts' => 5 )
         ); ?>
    		<?php while ( have_posts() ) : the_post(); ?>
    
    		<div class="post_type">
    
    		<?php if ( 'post-type' == get_post_type()  ) : ?>FEATURE<?php endif; ?>
    		<?php if ( 'post-type' == get_post_type()  ) : ?>REPORT<?php endif; ?>
    		<?php if ( 'post-type' == get_post_type()  ) : ?>OPINION<?php endif; ?>
    		<?php if ( 'post-type' == get_post_type()  ) : ?>BOOKMARK<?php endif; ?>
    		</div>
    
    		<a href="<?php the_permalink(); ?> "><?php the_title(); ?></a>
    
    		<div class="excerpt">
    		<?php echo get_the_excerpt(); ?>
    		</div>
    
    		<?php endwhile; ?>
  3. artlover578
    Member
    Posted 9 months ago #

    dont forget to replace post type with your custom post type name

Reply

You must log in to post.

About this Topic