WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

Is there an easy way to highlight search results based on post_type?

I am using Job Manager plugin and when a site search is performed, I want to simply add a note e.g. (Job) next to the Job Results.

share|improve this question
up vote 1 down vote accepted

i think you can PHP it using an if statement.. like so:

Say this is the loop.. (simple one i know):

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    $post_type = get_post_type_object( get_post_type($post) );
    $post_type_name = $post_type->labels->singular_name

    if ($post_type_name == 'example') {
    echo '<div class="highlight searchResults">';
    } else {
    echo '<div>';

<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

Dont forget to change the 'example' with the singular name of the custom post type you are checking for in the search restuls...

Hope this helps :)

share|improve this answer

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.