Skip to content

Instantly share code, notes, and snippets.

@dexit
Forked from KimJoyFox/functions.php
Created April 22, 2024 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dexit/fd4444271e2635cbef70e55ced15056c to your computer and use it in GitHub Desktop.
Save dexit/fd4444271e2635cbef70e55ced15056c to your computer and use it in GitHub Desktop.
Wordpress: using Excerpts from Advanced Custom Fields on the Search Results Page
function excerpt_function($ID, $searchTerms) {
global $wpdb;
$thisPost = get_post_meta($ID);
foreach ($thisPost as $key => $value) {
if ( false !== stripos($value[0], $searchTerms) ) {
$found = substr(strip_tags($value[0]), 0, 150);
echo $found . ' ...';
}
}
}
if (has_excerpt() ){
the_excerpt();
} else {
excerpt_function($post->ID, $_GET['s']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment