• I am trying to show the most recent post from 2 different post types. I can get it to show the most recent post from one of them bot not look at both and get the most recent of the 2. Below is the code that I am using any help would be much appreciated.

    <?php $recent = new WP_Query('outtakes&outtake_category=outdoor-recreation',
    	   'adirondack_almanac&adirondack_almanac_category=outdoor-recreation'); ?>
    <?php $count = 0; ?>
    <?php while( $recent->have_posts() ) : $recent->the_post(); ?>
    <?php $count++; ?>
      <?php if ($count < 2) : ?>
          <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php
    if ( has_post_thumbnail()):
        the_post_thumbnail( 'feed-fixed' );
    endif;  ?></a>
    
              <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    <?php echo wp_trim_words( get_the_excerpt(), 20 ); ?>
     <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">>>More</a>
       <?php else : ?>
    
    <?php endif; ?>
    <?php endwhile; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • You said, you want to get posts from 2 post type. So you need to use query like this>>
    new WP_Query(‘array(‘post_type’ => array(‘post_type1′,’post_type2′)……’)

    Thread Starter sdesigns

    (@sdesigns)

    Thank you so I now have the below code wich is showing the corect most recent post from the 2 post typs but how would I set it so that it is showing from a specific catigory in each of the post typs say outdoor-recreation.

    <?php
          $recentPosts = new WP_Query(array('showposts' => 1, 'post_type' => array('outtakes','adirondack_almanac')));
    while( $recentPosts->have_posts() ) :
        $recentPosts->the_post();?>
    
       <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php
    if ( has_post_thumbnail()):
        the_post_thumbnail( 'feed-fixed' );
    endif;  ?></a>
        <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    <?php echo wp_trim_words( get_the_excerpt(), 20 ); ?>
     <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">>>More</a>
    
    <?php endwhile; ?>

    Thank you for your help

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show 1 recent post from 2 custom post types’ is closed to new replies.