Make WordPress Core

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's profile 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)

class-wp-query.php.diff (660 bytes) - added by mgibbs189 7 years ago.
class-wp-query.php patch
class-wp-query.php.2.diff (619 bytes) - added by mgibbs189 7 years ago.

Download all attachments as: .zip

Change History (8)

@mgibbs189
7 years ago

class-wp-query.php patch

#1 @mgibbs189
7 years ago

  • Keywords has-patch dev-feedback added

#2 @mgibbs189
7 years ago

  • Keywords dev-feedback removed
  • Version trunk deleted

#3 @mgibbs189
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 @boonebgorges
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:

Thanks!

#5 @mgibbs189
7 years ago

  • Keywords has-patch added; needs-patch removed

@boonebgorges Great feedback, thank you. I've attached an updated patch. Please let me know if it looks OK.

#6 @boonebgorges
7 years ago

  • Resolution set to fixed
  • Status changed from new to closed

[40923] missed the ticket.

Note: See TracTickets for help on using tickets.