Home › Forums › Front-end Issues › Beginners question "Excerpt in Search results list"
Hi,
i’m using acf 5 Pro. On my site VDT-online-neu.de 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 https://codex.wordpress.org/Plugin_API/Filter_Reference/get_the_excerpt
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(); ?>
</div>
</div>
<?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>'; ?>
</div><!--/.post-list-->
<?php endif; ?>
<?php get_template_part('parts/pagination'); ?>
<?php endif; ?>
</div><!--/.pad-->
</section><!--/.content-->
<?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.
The topic ‘Beginners question "Excerpt in Search results list"’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.