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.

I have custom post types and would like to display the different results based upon a users search meta.

I have three custom post types that are styled differently and want to return the search results based upon their respective styles, not the generic page link and excerpt that it currently shows. could I use is_search()?

<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
    <?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
    <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'bsq' ) ); ?>
    <?php
        wp_link_pages( array(
            'before' => '<div class="page-links">' . __( 'Pages:', 'bsq' ),
            'after'  => '</div>',
        ) );
    ?>
</div><!-- .entry-content -->
<?php endif; ?>
share|improve this question
1  
Can you rephrase you 2nd sentence? Not sure I'm understanding the question. –  Eckstein Jun 17 '13 at 9:14
    
Sorry, I have three custom post types that are styled differently and want to return the search results based upon their respective styles, not the generic page link and excerpt that it currently shows. could I use is_search() to query the $_GET search or is that wrong? –  user1888564 Jun 17 '13 at 9:25
add comment

2 Answers

up vote 0 down vote accepted

is_search() is going to return TRUE on every search you perform, so that won't do what you need if I understand correctly. You'll have to use a post_type conditional tag. But it shouldn't be too difficult with something like

if (is_search()) {
if (get_post_type() == 'type_1') {
    //Do the right styling
} else if (get_post_type() == 'type_2') {
    //Do different styling
}//endif
}//endif

etc etc

Hopefully that's what you're looking for.

share|improve this answer
    
should I try with this in the search.php page or the content.php? –  user1888564 Jun 17 '13 at 9:36
add comment

Use post_class() function by Wordpress core. Read the documentation and you'll get there. http://codex.wordpress.org/Function_Reference/post_class

share|improve this answer
add comment

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.