Permalink
Browse files

Make wfx_excerpt() work outside of a loop/query

By supplying the optional new $id parameter to wfx_excerpt() you can now grab an excerpt anywhere, even outside a loop/query (cool!)
  • Loading branch information...
1 parent f431c7f commit 3d2673bd48fb725ac5b70d9996d3d4fce23f476e @Jonnyauk committed Dec 6, 2016
Showing with 14 additions and 1 deletion.
  1. +1 −0 functions.php
  2. +13 −1 wf-includes/wf-display-functions.php
View
@@ -1071,6 +1071,7 @@
/**
* Display excerpt of post content inside the loop or custom query.
+ * Can work outside of a loop too by supplying optional $id parameter.
* Note that output is run through esc_html() already, so no need to escape again thanks!
*
* @since 0.85
@@ -1567,6 +1567,7 @@ private function get_clean_theme_name() {
/**
* Display excerpt of post content inside the loop or custom query.
+ * Can work outside of a loop too by supplying optional $id parameter.
* Note that output is run through esc_html() already, so no need to escape again thanks!
*
* @since 0.85
@@ -1593,7 +1594,18 @@ function wf_excerpt($args) {
$id = ( is_numeric($id) ) ? $id : null;
- $content = get_the_excerpt( $id );
+ // Deal with grabbing the excerpt by ID when outside of a loop
+ if ( !empty($id) ) {
+
+ setup_postdata($id);
+ $content = get_the_excerpt( $id );
+ wp_reset_postdata();
+
+ } else {
+
+ $content = get_the_excerpt( $id );
+
+ }
if ( has_excerpt() && $full_excerpt == 'Y' ) {

0 comments on commit 3d2673b

Please sign in to comment.