Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am creating a site which uses normal posts for a blog and the a custom post type for events(generated by the events plugin). I have successfuly used different queries to grab both but I want to combine them into one query. Have tried various things with no luck.

Here is query for blog:

<?php $mainFeatures = array( 'numberposts' => -1, 'order'=> 'DESC', 'orderby' => 'post_date');
 $postslist = get_posts( $mainFeatures );
 foreach ($postslist as $post) :  setup_postdata($post); ?>            
      <!-- stuff from post-->
 <?php endforeach; ?>

Here is query for events:

 <?php query_posts(array('post_type'=>array(TribeEvents::POSTTYPE), 'numberposts' => -1,'order' => 'ASC')); ?>
 <?php while (have_posts()) : the_post(); ?>
      <!-- stuff from post-->
 <?php endwhile;?>

Have tried this but again only gets the events:

 <?php $tryone = query_posts(array('post_type'=>post, 'posts_per_page'=> 18)); ?>
 <?php $trytwo = query_posts(array('post_type'=>array(TribeEvents::POSTTYPE))); ?>
 <?php $all_posts = array_merge( $tryone, $trytwo ); ?>

 <?php query_posts($all_posts); ?>
 <?php while (have_posts()) : the_post(); ?>
 <p>stuff</p>
 <?php endwhile;?>
share|improve this question
1  
One has a DESC order and the other is ASC. I don't think you an do both, but otherwise you can pass an array of post types to the post_type parameter. –  helgatheviking Jan 19 '13 at 13:51
    
@helgatheviking i tried this but it only pulled the events, not the normal posts: <?php $args = array('post_type'=>array('posts', TribeEvents::POSTTYPE)); ?> <?php query_posts($args); ?> <?php while ( have_posts() ) : the_post(); ?> <p>test</p> <?php endwhile;?> –  Paul Elliot Jan 19 '13 at 14:23
    
That's because the post post type is simply post and not the plural. –  helgatheviking Jan 19 '13 at 15:21

1 Answer 1

up vote 2 down vote accepted

I think you are using the wrong post_type for regular posts.

$args = array('post_type'=>array('post', TribeEvents::POSTTYPE));  

// The Query
$the_query = new WP_Query( $args );

// The Loop
while ( $the_query->have_posts() ) :
    $the_query->the_post();
    echo '<li>' . get_the_title() . '</li>';
endwhile;

// Restore original Post Data
wp_reset_postdata();
share|improve this answer
    
Cheers, it seems to work but only grabs the events and posts in limited number, it onl gets a total of 4 whereas there is 18 posts and 2 events. –  Paul Elliot Jan 19 '13 at 16:00
    
Edit the answer to use the proper WP_Query() instead of query_posts(), and I'll upvote. :) –  Chip Bennett Jan 19 '13 at 16:10
    
Good point @ChipBennett. Done. –  helgatheviking Jan 19 '13 at 16:24
    
Upvoted. :) Note: you don't need to call wp_reset_query(), since you're no longer touching the main query. Calling wp_reset_postdata() suffices. –  Chip Bennett Jan 19 '13 at 16:38
    
cheers for the help, that worked great - I just realised that the limit of 4 was being caused by the basic reading settings in wordpress duh. –  Paul Elliot Jan 19 '13 at 16:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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