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.

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

1 Answer 1

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(); ?>

<?php 
    $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>
</div>

<?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

 
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.