From bb0354dda13c6f176eccd71c8a0adaf5aa98a469 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 23 Jun 2017 01:54:59 +0000 Subject: [PATCH] Introduce `loop_no_results` action. This action fires when a `WP_Query` query returns no results. Props mgibbs189. Props #40850. git-svn-id: https://develop.svn.wordpress.org/trunk@40923 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-query.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index e20d574409..a578f9afc7 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -3144,6 +3144,15 @@ class WP_Query { do_action_ref_array( 'loop_end', array( &$this ) ); // Do some cleaning up after the loop $this->rewind_posts(); + } elseif ( 0 === $this->post_count ) { + /** + * Fires if no results are found in a post query. + * + * @since 4.9.0 + * + * @param WP_Query $this The WP_Query instance. + */ + do_action( 'loop_no_results', $this ); } $this->in_the_loop = false;