Skip to content

Instantly share code, notes, and snippets.

@KimJoyFox
Created September 14, 2018 19:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KimJoyFox/2a4a7192a10c03a96ec1711f61558113 to your computer and use it in GitHub Desktop.
Save KimJoyFox/2a4a7192a10c03a96ec1711f61558113 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