Opened 7 years ago
Closed 7 years ago
#40850 closed enhancement (fixed)
WP_Query->have_posts() -- add action if no results are found
Reported by: | mgibbs189 | Owned by: | |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Query | Keywords: | has-patch |
Focuses: | Cc: |
Description
We can hook into loop_start
and loop_end
when results are found, but there's no loop_no_results
hook. This patch adds that!
Attachments (2)
Change History (8)
#3
@
7 years ago
@SergeyBiryukov @swissspidy Howdy, could I please get dev feedback on this one?
We're doing template auto-detection for FacetWP, and this loop_no_results
action will allow us to "latch on" to the template when no results are found... which isn't currently possible via loop_start
or loop_end
.
#4
@
7 years ago
- Keywords needs-patch added; has-patch removed
- Milestone changed from Awaiting Review to 4.9
Hi @mgibbs189 - Sorry for the delay in reviewing the patch.
Adding an action here seems like a fine idea, and your technique for firing the action - in an elseif ( 0 === $this->post_count )
clause - seems like the most efficient way to do it.
A couple small requests on the patch:
- The
@since
annotation needs updating for 4.9, and we generally use the three-digit format:@since 4.9.0
. See https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/#since-section-changelogs - The use of
do_action_ref_array( ..., array( &$this ) )
is a legacy of PHP4 support.do_action( ..., $this )
should be sufficient - the object ought to be passed by reference automatically.
Thanks!
Note: See
TracTickets for help on using
tickets.
class-wp-query.php patch