Home Forums Front-end Issues Beginners question "Excerpt in Search results list"


Beginners question "Excerpt in Search results list"

  • Hi,

    i’m using acf 5 Pro. On my site I created 2 field groups to show pigeons and the supporting organization.

    If a visitor searches for a pigeon namend “Arabische Trommeltaube”, WordPress list’s all posts and pages about the pigeon. But for my pages, created by myself for the pigeon description, there is no excerpt, because i didn’t filled the wordpress field “content”.

    I want to show a static text as excerpt like “Die Beschreibung der Rassetaube xyz”. xyz should be the value of another acf field.

    Any ideas?

    Thx for your help! Greets, Juergen

  • In your search results page

    $excerpt = get_the_excerpt();
    if (!$excerpt) {
      $excerpt = get_field('your-excerpt-field');

    of add a “get_the_excerpt” filter in functions.php that does something similar

  • Thx, John. Looks like a little bit to difficult for me.

    Is it another idea to fill the default field “content” with another acf field?

  • Can you show me where to place your code in my search.php? Thx!

    <?php get_header(); ?>
    <section class="content">
    	<?php hu_get_template_part('parts/page-title'); ?>
    	<div class="pad group">
    		<div class="notebox">
    			<?php _e('For the term','hueman'); ?> "<span><?php echo get_search_query(); ?></span>".
    			<?php if ( !have_posts() ): ?>
    				<?php _e('Please try another search:','hueman'); ?>
    			<?php endif; ?>
    			<div class="search-again">
    				<?php get_search_form(); ?>
    		<?php if ( have_posts() ) : ?>
    			<?php if ( hu_is_checked('blog-standard') ): ?>
    				<?php while ( have_posts() ): the_post(); ?>
    					<?php get_template_part('content-standard'); ?>
    					<?php endwhile; ?>
    			<?php else: ?>
    			<div class="post-list group">
    				<?php global $wp_query; echo '<div class="post-row">'; while ( have_posts() ): the_post(); ?>
              <?php get_template_part('content'); ?>
            <?php if( ( $wp_query->current_post + 1 ) % 2 == 0 ) { echo '</div><div class="post-row">'; }; endwhile; echo '</div>'; ?>
    			<?php endif; ?>
    			<?php get_template_part('parts/pagination'); ?>
    		<?php endif; ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
  • Not sure what theme your using, but the template that you need to edit is included by this line.

    <?php get_template_part('content-standard'); ?>

    I would recommend copying that template to a new file, for example `content-search’ and then modifying that since you don’t want to change the template for all of your content.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Beginners question "Excerpt in Search results list"’ is closed to new replies.