0

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; ?>
2
  • 1
    Can you rephrase you 2nd sentence? Not sure I'm understanding the question.
    – Eckstein
    Jun 17, 2013 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? Jun 17, 2013 at 9:25

2 Answers 2

0

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.

1
  • should I try with this in the search.php page or the content.php? Jun 17, 2013 at 9:36
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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