# Conditional for Custom Post Types

I have a query that pulls custom post types and regular posts, but how could I tell it to offset just one post type in the query?

My query:

<?php query_posts( array(
'posts_per_page' => 10,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
));
?>


But I want it to include:

If 'Post Type' exists, offset by 1.

Any help is greatly appreciated!

-
What exactly do you mean by "offset by 1"? Offset the query_posts by 1 post? And also, why wouldn't the post type exist if you declared it? –  Kevin Langley Jr. Nov 7 '11 at 20:27
The query above includes regular posts on various other post types. I want to be able to offset one particular post type out of the query. –  Erika Nov 7 '11 at 21:07

What you're trying to do is not going to be able to be done via a single query. Not sure why you want to get all posts of all post types.

But, in order to do what you want, you will have to just have php logic check if it is the first post in that post type and if so, skip it.

-
I'll do my best to explain. –  Erika Nov 9 '11 at 17:06
My site is for an online radio show. I have 2 queries on the homepage. The first query grabs the newest episode information and is displayed at the top of the page along with the video player for the live show. The second queries everything else which includes a custom post type called 'stories', past episodes and regular posts. As it is now, when I post a new episode is shows up perfectly at the top of the page, but is duplicated in the second query. I don't want the newest episode post type to show up in the second query but I do want past episodes to appear. Make sense? –  Erika Nov 9 '11 at 17:12
based on this explanation, your best solution is to just pass in the post_id of the newest episode as an 'exclude' argument to your second query. –  prettyboymp Jan 21 '12 at 13:57

Not quite sure what you mean by If 'Post Type' exists but could you do something like:

<?php
query_posts(
array(
'posts_per_page' => 10,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
if("Post Type exists?"){ 'offset' => 1 }
));

? >

-
This didn't work unfortunately. :( –  Erika Nov 9 '11 at 17:05

As Kevin Langley Jr. says, you'll probably need to use php logic to do this.

You'll need to modify this for you query but in your loop try adding a flag for the post type:

$firstOfPostType = true; //set your flag to true initially if( have_posts() ) : while( have_posts() ) : the_post(); if($firstOfPostType == true && $post->post_type == "YOUR POST TYPE" ){ continue;// Skip this iteration$firstOfPostType = false;// set this to false so it doesn't run again.
}


[edit: to add formatted code as supplied in comments]

This may work. Depending on what's in content-POSTFORMAT.php which is brought in by get_template_part() you may need to put the code in there.

<?php

query_posts(
array(
'posts_per_page' => 10,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
)
);

$posts = get_posts( array ( 'numberposts' => '10', 'post_type' => array ( 'post', 'episodes', 'featured-stories' ), )) ;$firstOfPostType = true;
foreach ($posts as$post) : start_wp();

if( $firstOfPostType == true &&$post->post_type == "episodes"){
$firstOfPostType = false; continue; } ?> <?php static$count2 = 0;
if ($count2 == "10") { break; } else { ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php$count2++; } ?>
<?php endforeach; ?>

-
Not sure how to incoporate that with the loops I have on my page: –  Erika Nov 10 '11 at 0:33
<?php query_posts( array( 'posts_per_page' => 10, 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ), )); ?> <?php $posts = get_posts( array ( 'numberposts' => '10', 'post_type' => array ( 'post', 'episodes', 'featured-stories' ), )); foreach ($posts as $post) : start_wp(); ?> <?php static$count2 = 0; if ($count2 == "10") { break; } else { ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php$count2++; } ?> <?php endforeach; ?> –  Erika Nov 10 '11 at 0:35
I've put code in the question above. I think this should work though not all your code is there because there's an include (get_template_part()). The loop on your get_posts() query is a bit odd too. I'm pretty sure wp-start() is deprecated & you shouldn't need the counter in your loop since you have numberposts in your query... but if it's working... –  patnz Nov 10 '11 at 3:24