I have from my perspective a complicated loop. Code below.

<!-- *** Check Mass List (Custom Post Type) *** -->

<!-- *** End Mass List (Custom Post Type) *** -->     
<?php if (have_posts()) : ?>
<?php $new = 'first'; ?>
<?php while (have_posts()) : the_post(); ?>
<?php if( $new == 'first' && !is_paged() ) : $new = 'not-first';  ?>
<p class="timedate"><?php the_date('F jS, Y'); ?></p>
<article id="post-<?php the_ID(); ?>" class="latest">
<h1><?php the_category(', '); ?></h1>
<?php ($post == $posts[0] && !is_paged()) ? the_content('', 'FALSE') : the_excerpt() ; ?>
<p><?php the_tags('Tags: ', ', ', '<br>'); ?></p>
<?php else : ?>
<p class="timedate"><?php the_date('F jS, Y'); ?></p>
<article id="post-<?php the_ID(); ?>">
<h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_category(' '); ?></a></h1>
<div class="shortstuff">
<?php $tags = get_the_tags();
$html = '<div class="post_tags">';
foreach ( $tags as $tag )
$tag_link = get_tag_link( $tag->term_id );

$html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>     <h2>{$tag->name}</h2></a>";
$html .= "<p>$tag->description</p>"."";

$html .= '</div>';
echo $html;?>
<?php ($post == $posts[0] && !is_paged()) ? the_content('', 'FALSE') : the_excerpt() ; ?>
<?php endif; ?>    
<?php endwhile; ?>
<?php posts_nav_link('&nbsp;&bull;&nbsp;'); ?>
<?php else : ?>
<h1>Not Found</h1>
<p>Sorry, but the requested resource was not found on this site.</p>
<?php get_search_form(); ?>
<?php endif; ?>

This loop as you may have read does the following: Displays the latest post made then goes on to display the older posts. The Latest post is displayed in another style as opposed to the older posts.

I would like to add a 3rd check to this loop for a custom post type. So wordpress checks all 3 arguments then displays them based in the order on what date & time they were posted.

Example of the output logic could be. July 5 - Latest, custom post type, other posts. July 6 - custom post type, newest post then oldest post.

So everything works as my code shows in the sample. Only change would be the loop checks to see if a custom post type exists for that day and if it does it inserts it into the output.


  • 1
    It is unclear what you want to do, what happens after the check?
    – Wyck
    Jul 8, 2011 at 5:58
  • Imagine this being a normal loop. All I want is there to be another <?php else ; ?> statement in there to check to see if a custom post type named "Mass" was used to create a post rather than the normal method of creating a post. I've tried to add this and I keep getting errors so I'm obviously not adding it correctly. And that's what I need help with.
    – Kapitol
    Jul 8, 2011 at 8:47
  • I'll give this another 4 hours then I'll close it.
    – Kapitol
    Jul 8, 2011 at 13:59
  • Still unclear, what exactly do you want to do after checking for 'Mass', do you just want to return true or false, include it in the loop, flash a giant banner saying 'yahoooo'?
    – Wyck
    Jul 8, 2011 at 16:41
  • Edited original text, hopefully it will provide some clarification.
    – Kapitol
    Jul 9, 2011 at 16:28

1 Answer 1


To alter your default or main loop you can add query_posts before the loop runs.

http://codex.wordpress.org/Class_Reference/WP_Query ( parameters)

For example in your above code, to include all posts including custom posts types you would write;

<?php query_posts( 'post_type=any'); ?>
<?php while (have_posts()) : the_post(); ?>
//rest of your code from above

If you want to just include all default posts and 1 custom post type called "mass_list" , I recommend using WP Query over query_posts in this case.

<?php $query = new WP_Query( array( 'post_type' => array( 'post',  'mass_list' ) ) ); ?>
<?php while (have_posts()) : the_post(); ?>
    //rest of your code from above

You can drill down by looking at the parameters of WP Query in the link above, as you can see the options of WP Query allow for a lot of custom output.

  • Thanks for responding. That does show the CPT. However it's not compatible with the code I have. Starting where it says, foreach ( $tags as $tag ), that causes my post in the output to kick back an error where it doesn't show the tag and display an error stating it. The problem stems from the idea that a CPT wont or cant show Tags. Checking the for the CPT would almost need to be separated by an else statement so it doesn't check to see if it has a Tag when it calls for a CPT.
    – Kapitol
    Jul 9, 2011 at 21:36
  • A CPT can show a tag, but that is outside the scope of your original question.
    – Wyck
    Jul 9, 2011 at 23:03
  • You win, I'll close it and search elsewhere.
    – Kapitol
    Jul 10, 2011 at 0:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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