WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On lines 4-6, I've inserted three conditional statements to determine which post type the post is in so I can insert a span which I will use to insert an image. The way I wrote it isn't working. What statement would I need to use? And is there a simpler way to set this up?

    <section id="main">
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <article class="search-post" id="post-<?php the_ID(); ?>">
            <?php if (is_singular('projects')) {echo'<span class="search-projects"></span>';} ?>
            <?php if (is_singular('videos')) {echo'<span class="search-videos"></span>';} ?>
            <?php if (is_singular('friends')) {echo'<span class="search-friends"></span>';} ?>
            <h2><?php the_title(); ?></h2>
            <section class="search-entry">
                <?php the_excerpt(); ?>
        <?php endwhile; endif; ?>
        <?php my_paginate_links(); ?>

For categories, I usually use in_category. Is there something like an in_post_type?

share|improve this question
up vote 2 down vote accepted

If you use is_singular(), you're also checking for if it's a singular item on the page. Do $post->post_type == 'my-post-type' instead.

BTW: if you use post_class() you get this and more done automatically.

share|improve this answer
Actually according to Codex is_singular() with post type passed should check for that specific post type. I am not sure why would it fail in this specific case. Edit Scratch that, got confused for a moment. is_singular() check for global query, not global post. So not suitable for loop of multiple posts. – Rarst Feb 23 '11 at 13:14

Your Answer


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.