WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 5 months ago

#30250 assigned enhancement

Add filter for query used in `wp_count_posts()`

Reported by: danielbachhuber Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: needs-patch
Focuses: Cc:
PR Number:

Description

Use case: if my list table is filtering to a specific taxonomy term, I'd like my view counts to reflect that filter.

The existing filter added in #16603 still means I need a lot of duplicate code, and two queries.

Attachments (1)

30250.diff (3.0 KB) - added by iworks 5 years ago.
Show correct numbers of posts.

Download all attachments as: .zip

Change History (8)

#1 @iworks
5 years ago

Partial solution.

Do not count properly for sticky posts.

Why?

Sticky post are counted in different place.

But if this direction is ok, just help me to finish this task.

How handle this different place? wp-admin/includes/class-wp-posts-list-table.php line 83?

@iworks
5 years ago

Show correct numbers of posts.

#2 follow-up: @minderdl
5 years ago

I'm not sure about this approach. The line with the counts is above the filters. Therefore, it's not on the same level.

What you are proposing is to add All/Draft/Pending/Published as another filter category. For me, it would make more sense to move the line with the counters below the filters then. And you need an additional "Reset filters" button then.

This is what the current All/Draft/Pending/Published links are acutally doing: resetting the filters!

So, I would be reluctant to include your proposal. But I'm far from being a core developer :-)

#3 @ipm-frommen
5 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

#4 @DrewAPicture
5 years ago

  • Owner set to iworks
  • Status changed from new to assigned

#5 @DrewAPicture
5 years ago

  • Keywords needs-refresh added

Patch needs a refresh.

#6 in reply to: ↑ 2 @SergeyBiryukov
5 years ago

  • Keywords needs-patch added; has-patch needs-testing needs-refresh removed

Replying to minderdl:

I'm not sure about this approach. The line with the counts is above the filters. Therefore, it's not on the same level.

I think this ticket is about a custom list table built by a custom query, not about the All dates/All categories filters.

30250.diff does not seem like a correct solution here.

We should introduce something like 'posts_clauses' filter, but specific to the query in wp_count_posts().

We could also add a third parameter, $args, and use WP_Query to get post IDs and use them in the WHERE clause, but that seems out of the scope of this ticket.

#7 @wonderboymusic
4 years ago

  • Keywords good-first-bug removed
  • Owner iworks deleted
Note: See TracTickets for help on using tickets.