-2

Wondering how to return only excerpts on a search.

function get_the_excerpt( $deprecated = '' ) {
    if ( !empty( $deprecated ) )
        _deprecated_argument( __FUNCTION__, '2.3' );

    $post = get_post();
    if ( empty( $post ) ) {
        return '';
    }

    if ( post_password_required() ) {
        return __( 'There is no excerpt because this is a protected post.' );
    }

    /**
     * Filter the retrieved post excerpt.
     *
     * @since 1.2.0
     *
     * @param string $post_excerpt The post excerpt.
     */
    return apply_filters( 'get_the_excerpt', $post->post_excerpt );
}

Do I just put this function within the Search loop?

  • Where are you using the excerpt? Can you show your code to give context to the proper answer? – jgraup Jan 8 '16 at 22:23
0

you will just do the the_excerpt(); in search loop

like this

Following is the code that goes in search.php

<?php if(have_posts()):while (have_posts()):the_post();?>
    <a href="<?php the_permalink(); ?>">
       <h3 class="title-heading"><?php the_title(); ?></h3>
       <?php the_excerpt(); ?>          
    </a>    
<?php
    endwhile;
    else:"No matching result found";
    endif;
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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