-
-
Save dexit/fd4444271e2635cbef70e55ced15056c to your computer and use it in GitHub Desktop.
Wordpress: using Excerpts from Advanced Custom Fields on the Search Results Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 . ' ...'; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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