Opened 9 years ago
Closed 9 years ago
#40850 closed enhancement (fixed)
WP_Query->have_posts() -- add action if no results are found
| Reported by: | mgibbs189 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.9 |
| Component: | Query | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
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
@
9 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
@
9 years ago
- Keywords needs-patch added; has-patch removed
- Milestone Awaiting Review → 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
@sinceannotation 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!
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
class-wp-query.php patch