Opened 9 years ago
Last modified 8 years ago
#42082 new enhancement
Support compare custom fields in WP_Meta_Query
| Reported by: | mariovalney | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Query | Version: | 4.9.4 |
| Severity: | normal | Keywords: | needs-patch |
| Cc: | Focuses: |
Description
The syntax of WP_Meta_Query currently is limited to values you already know.
It's not possible to compare between two meta_values:
SELECT posts WHERE meta_value_one > meta_value_two
I propose allow compare two meta_fields. For example, the pseudocode above would be represented as a meta_query argument that looks like this:
<?php array( 'key' => 'meta_value_one', 'value' => 'meta_value_two', 'compare' => '>', 'type' => 'META_VALUE' ),
A workaround can be found here and here hahaha.
Feedback is welcome.
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Fixing the proposed example (the parametes should be the key, not the value):
And proposing another approach to keep consistency in 'type' parameter (because its values are SQL data types) maybe we can add a new parameter (which will be ignored if "value" is presented):