Make WordPress Core

Opened 4 years ago

Last modified 2 months ago

#55287 new feature request

Allow for DISTINCT in WP_Query method

Reported by: simbaclaws's profile simbaclaws Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Query Keywords: needs-patch reporter-feedback
Focuses: Cc:

Description (last modified by sabernhardt)

Dear wordpress developers,

Currently I'm working with a plugin to create designs.
This plugin has an element called a repeater element that basically makes use of the core WP_Query method in order to fetch custom post types or normal post types.

However, since I'm using this page builder or theme builder, I am in no way capable of using DISTINCT within the filter https://developer.wordpress.org/reference/hooks/posts_distinct/
Because this requires me to send the WP_Query instance, which is basically only used within the repeater element and can not be set to a variable in this particular case.

This means I'll have to rebuild everything through code, instead of being able to use my page or theme builder.

Now I get the idea of saying this is a bug with the page or theme builder plugin.
But in fact, what I want to know is why are we using a filter to create a DISTINCT query inside of WP_Query? Isn't it possible to implement this inside of the WP_Query arguments instead? I basically want to say: fetch posts with unique titles. This seems much more logical as the SQL query is build from WP_Query...

I've already looked through the entire codex, and couldn't find any possible parameter that could be used for this...

My question to you is: Can this please be added to WordPress core?
I find it highly frustrating that WP_Query doesn't have this sort of capabilities out of the box.

Change History (2)

#1 @sabernhardt
2 months ago

  • Component changed from Posts, Post Types to Query
  • Description modified (diff)
  • Version 6.0 deleted

#2 @jorbin
2 months ago

  • Keywords reporter-feedback added

Hi @simbaclaws, welcome to WordPress Trac. Sorry it's taken so long for someone to respond.

Based on your post, it seems like you may be encountering a problem with a plugin rather than WordPress Core. If I am incorrect, can you share minimum example code that demonstrates the problem you are encountering?

Note: See TracTickets for help on using tickets.