Commit Graph

112 Commits

Author SHA1 Message Date
Boone Gorges
7bde88d02e Modify `meta_query orderby syntax to use array keys as clause "handles".
The implementation of `meta_query` orderby introduced in [31312] put clause
identifiers into a 'name' parameter of the clause. For greater clarity, this
changeset updates the syntax to use the associative array key used when
defining `meta_query` parameters, instead of the 'name' parameter.

Props Funkatronic, DrewAPicture.
Fixes #31045.
Built from https://develop.svn.wordpress.org/trunk@31340


git-svn-id: http://core.svn.wordpress.org/trunk@31321 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-05 19:38:23 +00:00
Boone Gorges
ca30c725a0 Improve support for ordering WP_Query results by postmeta.
`WP_Meta_Query` clauses now support a 'name' parameter. When building a
`WP_Query` object, the value of 'orderby' can reference this 'name', so that
it's possible to order by any clause in a meta_query, not just the first one
(as when using 'orderby=meta_value'). This improvement also makes it possible
to order by multiple meta query clauses (or by any other eligible field plus
a meta query clause), using the array syntax for 'orderby' introduced in [29027].

Props Funkatronic, boonebgorges.
Fixes #31045.
Built from https://develop.svn.wordpress.org/trunk@31312


git-svn-id: http://core.svn.wordpress.org/trunk@31293 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-01-31 15:48:24 +00:00
Scott Taylor
bc55996a0b @param cleanup:
* `get_metadata()` will return literally anything, needs to be `mixed`
* `wp()` and `WP_Query::__construct()` no longer just take a query string
* Clarify a few others

See #30799.

Built from https://develop.svn.wordpress.org/trunk@31212


git-svn-id: http://core.svn.wordpress.org/trunk@31193 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-01-16 19:03:23 +00:00
Scott Taylor
60b0cd7943 The keyword elseif should be used instead of else if so that all control keywords look like single words.
This was a mess, is now standardized across the codebase, except for a few 3rd-party libs. 

See #30799.

Built from https://develop.svn.wordpress.org/trunk@31090


git-svn-id: http://core.svn.wordpress.org/trunk@31071 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-01-08 07:05:25 +00:00
Scott Taylor
42f5acd869 Improve some docs for @param. Remove an unneeded $wpdb global import.
See #30799.

Built from https://develop.svn.wordpress.org/trunk@30979


git-svn-id: http://core.svn.wordpress.org/trunk@30965 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-12-20 20:56:22 +00:00
Boone Gorges
5eeea164ef In WP_Meta_Query, interpret 'value' correctly when used with EXISTS/NOT EXISTS.
As in earlier versions, EXISTS with a value is equivalent to '=', while NOT
EXISTS should always ignore 'value'.

Props barrykooij.
Fixes #30681 for trunk.
Built from https://develop.svn.wordpress.org/trunk@30846


git-svn-id: http://core.svn.wordpress.org/trunk@30836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-12-14 19:01:26 +00:00
Drew Jaynes
23707b1ada Convert various uses of (optional) in core parameter descriptions to use the style prescribed in the inline documentation standards for PHP.
The style for marking parameters optional in inline PHP docs is: `@param type $var Optional. Description. Accepts. Default.`, where Accepts can be omitted on a case-by-case basis.

Props coffee2code.
Fixes #30591.

Built from https://develop.svn.wordpress.org/trunk@30753


git-svn-id: http://core.svn.wordpress.org/trunk@30743 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-12-06 21:24:45 +00:00
John Blackbourn
d28823df33 Revert r30115 which was a breaking change for code which interacts with the return value of get_metadata() when no meta key is specified.
See #15030

Built from https://develop.svn.wordpress.org/trunk@30701


git-svn-id: http://core.svn.wordpress.org/trunk@30691 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-12-02 03:35:22 +00:00
Scott Taylor
a0df295f5c Improve various @param docs.
See #30224.

Built from https://develop.svn.wordpress.org/trunk@30674


git-svn-id: http://core.svn.wordpress.org/trunk@30664 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-11-30 23:24:25 +00:00
Drew Jaynes
d6e6dbf086 Docs Formatting: Backtick-escape inline code for all dynamic hook docs in wp-includes/meta.php.
Affects DocBlocks for the following hooks:
* `add_{$meta_type}_metadata`
* `add_{$meta_type}_meta`
* `added_{$meta_type}_meta`
* `update_{$meta_type}_metadata`
* `update_{$meta_type}_meta`
* `updated_{$meta_type}_meta`
* `delete_{$meta_type}_metadata`
* `delete_{$meta_type}_meta`
* `deleted_{$meta_type}_meta`
* `get_{$meta_type}_metadata`
* `delete_{$meta_type}meta`
* `deleted_{$meta_type}meta`
* `sanitize_{$meta_type}_meta_{$meta_key}`

See #30552.

Built from https://develop.svn.wordpress.org/trunk@30655


git-svn-id: http://core.svn.wordpress.org/trunk@30645 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-11-30 12:03:24 +00:00
Drew Jaynes
f6fd6e09b1 4.1 Docs Audit: Improve inline documentation for various WP_Meta_Query methods introduced or modified in 4.1.
See #30469.

Built from https://develop.svn.wordpress.org/trunk@30617


git-svn-id: http://core.svn.wordpress.org/trunk@30607 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-11-28 12:02:22 +00:00
Scott Taylor
106da1e9e6 In WP_Meta_Query->get_sql_for_clause(), the empty initialization of $where is dead code and can be removed.
See #30224.

Built from https://develop.svn.wordpress.org/trunk@30163


git-svn-id: http://core.svn.wordpress.org/trunk@30163 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-11-01 22:03:22 +00:00
Drew Jaynes
a929ac44e1 Relocate hook docs so they directly precede the hook lines moved into foreach statements in [30140].
It's necessary for hook docs to directly precede hook lines so the parser can correctly match them up. This change relocates hook docs for `update_{$meta_type}_meta`, `update_postmeta`, `updated_{$meta_type}_meta`, and `updated_postmeta`.

Fixes #11683.

Built from https://develop.svn.wordpress.org/trunk@30149


git-svn-id: http://core.svn.wordpress.org/trunk@30149 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-11-01 04:18:23 +00:00
Boone Gorges
c27548265e Pass all updated meta IDs to filters in update_metadata().
Props wonderboymusic.
Fixes #11683.
Built from https://develop.svn.wordpress.org/trunk@30140


git-svn-id: http://core.svn.wordpress.org/trunk@30140 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-11-01 02:39:24 +00:00
Drew Jaynes
66c47f29bb Correct references of @uses $wpdb in core documentation to use @global.
See #30191, [30105].
Fixes #30217.

Built from https://develop.svn.wordpress.org/trunk@30122


git-svn-id: http://core.svn.wordpress.org/trunk@30122 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-31 17:56:22 +00:00
Boone Gorges
93ae51e801 Unserialize get_metadata() results when 'key' is omitted.
Props mattkeys, nacin.
Fixes #15030.
Built from https://develop.svn.wordpress.org/trunk@30115


git-svn-id: http://core.svn.wordpress.org/trunk@30115 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-30 10:25:22 +00:00
Drew Jaynes
f8657d5890 Remove redundant and erroneous @uses tag from most core inline documentation.
Per our inline documentation standards, no further use of the `@uses` tag is recommended as used and used-by relationships can be derived through other means. This removes most uses of the tag in core documentation, with remaining tags to be converted to `@global` or `@see` as they apply.

Fixes #30191.

Built from https://develop.svn.wordpress.org/trunk@30105


git-svn-id: http://core.svn.wordpress.org/trunk@30105 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-30 01:05:24 +00:00
Boone Gorges
b137059656 Make orderby=meta_value compatible with meta_query when relation=OR.
Passing orderby=meta_value and meta_key=foo to WP_Query should require that
each matched post have a meta value with the key 'foo'. To make this
requirement compatible with meta_query params that have the relation OR, we
nest the meta_query param, and join it using AND to a meta_query clause
generated from the meta_key/meta_compare/meta_type query vars.

Fixes #25538.
Built from https://develop.svn.wordpress.org/trunk@29964


git-svn-id: http://core.svn.wordpress.org/trunk@29711 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-19 18:54:19 +00:00
Boone Gorges
09e1239ad6 Remove redundant table alias check in WP_Meta_Query.
Also adds documentation for 'meta_query_find_compatible_table_alias' filter.

See #24093.
Built from https://develop.svn.wordpress.org/trunk@29953


git-svn-id: http://core.svn.wordpress.org/trunk@29701 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-18 02:22:19 +00:00
Boone Gorges
4ca2996eff Bail from cleaning meta query clause when it's not an array.
Later isset() checks on string values were causing notices on PHP < 5.4.

Props jorbin.
See #29642.
Built from https://develop.svn.wordpress.org/trunk@29941


git-svn-id: http://core.svn.wordpress.org/trunk@29692 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-17 20:25:19 +00:00
Boone Gorges
9345e9ffa5 Overhaul SQL generating logic in WP_Meta_Query to avoid unnecessary table joins.
The logic used to generate clause SQL in `WP_Meta_Query` is somewhat arcane,
stemming mostly from an ongoing effort to eliminate costly table joins when
they are not necessary. By systematizing the process of looking for shareable
joins - as was done in `WP_Tax_Query` [29902] - it becomes possible to simplify
the construction of SQL queries in `get_sql_for_clause()`. Moreover, the
simplified logic is actually considerably better at identifying shareable
joins, such that certain uses of `WP_Meta_Query` will see joins reduced by 50%
or more.

Includes integration tests for a representative cross-section of the query
clause combinations that result in shared table aliases.

Props boonebgorges, sc0ttkclark.
See #24093.
Built from https://develop.svn.wordpress.org/trunk@29940


git-svn-id: http://core.svn.wordpress.org/trunk@29691 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-17 20:21:18 +00:00
Boone Gorges
d64b1ed955 Use only LEFT JOINs when a meta_query contains a NOT EXISTS clause.
Mixing LEFT and INNER JOIN in these cases results in posts with no metadata
being improperly excluded from results.

Props johnrom.
Fixes #29062.
Built from https://develop.svn.wordpress.org/trunk@29890


git-svn-id: http://core.svn.wordpress.org/trunk@29646 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-14 02:17:18 +00:00
Boone Gorges
d1d9915f07 Introduce support for nested queries in WP_Meta_Query.
Previously, meta query arguments could be joined by a single AND or OR relation.
Now, these queries can be arbitrarily nested, allowing clauses to be linked
together with multiple relations.

Adds unit tests for the new nesting syntax. Modifies a few existing unit tests
that were overly specific for the old SQL syntax. Backward compatibility with
existing syntax is fully maintained.

Props boonebgorges, DrewAPicture.
See #29642.
Built from https://develop.svn.wordpress.org/trunk@29887


git-svn-id: http://core.svn.wordpress.org/trunk@29643 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-13 22:03:18 +00:00
Andrew Nacin
9cbad29eb8 Meta Query: Revert [28659] (and [28665]) due to regressions.
props boonebgorges.
fixes #29285. see #25538.

Built from https://develop.svn.wordpress.org/trunk@29650


git-svn-id: http://core.svn.wordpress.org/trunk@29424 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-08-27 20:23:16 +00:00
Scott Taylor
eb66e40790 After [29339] and [29341], add more unit tests and less ambiguous type-checking before bailing in meta-related functions that expect a numeric value for $object_id.
Props SergeyBiryukov.
Fixes #28315.

Built from https://develop.svn.wordpress.org/trunk@29421


git-svn-id: http://core.svn.wordpress.org/trunk@29199 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-08-06 22:08:16 +00:00
Scott Taylor
0d2a5c437e Bail on update_user_meta() when $object_id is non-numeric.
Adds unit test.

Props jacklenox, wonderboymusic.
Fixes #28315.

Built from https://develop.svn.wordpress.org/trunk@29339


git-svn-id: http://core.svn.wordpress.org/trunk@29119 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-08-01 17:10:15 +00:00
Scott Taylor
05eeb16e30 Replace all uses of like_escape() with $wpdb->esc_like().
Props miqrogroove.
See #10041.

Built from https://develop.svn.wordpress.org/trunk@28712


git-svn-id: http://core.svn.wordpress.org/trunk@28528 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-06-10 00:44:15 +00:00
Scott Taylor
38819880ec Wrap individual meta query WHERE clases in parens, missed in 28659.
Props boonebgorges.
Fixes #25538.


Built from https://develop.svn.wordpress.org/trunk@28665


git-svn-id: http://core.svn.wordpress.org/trunk@28483 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-06-04 18:21:15 +00:00
Scott Taylor
a7c2180672 Fix SQL generation when meta_query has an 'relation' => 'OR' for its queries and wants to 'orderby' => 'meta_value'.
Adds unit test.

Props jackreichert.
Fixes #25538.


Built from https://develop.svn.wordpress.org/trunk@28659


git-svn-id: http://core.svn.wordpress.org/trunk@28477 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-06-04 05:48:14 +00:00
Scott Taylor
b539c1cd76 Add missing access modifiers to methods in WP_Meta_Query.
See #27881, #22234.

Built from https://develop.svn.wordpress.org/trunk@28522


git-svn-id: http://core.svn.wordpress.org/trunk@28348 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-05-19 06:35:14 +00:00
Scott Taylor
b2b25f7326 In update_metadata_by_mid(), $original_value is unused.
See #27882.

Built from https://develop.svn.wordpress.org/trunk@28328


git-svn-id: http://core.svn.wordpress.org/trunk@28156 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-05-06 21:29:26 +00:00
Drew Jaynes
a10a55cf87 Fix a typo in the deleted_{$meta_type}_meta hook description.
Props aliso.
Fixes #25826.

Built from https://develop.svn.wordpress.org/trunk@27723


git-svn-id: http://core.svn.wordpress.org/trunk@27560 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-25 20:34:15 +00:00
Drew Jaynes
97958a3c16 Inline documentation for hooks in wp-includes/meta.php.
Props raamdev and kpdesign.
Fixes #25826.

Built from https://develop.svn.wordpress.org/trunk@27698


git-svn-id: http://core.svn.wordpress.org/trunk@27537 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-25 08:56:14 +00:00
Scott Taylor
0115ba2f30 When using meta_query in a WP_Query, passing NOT EXISTS or '' to compare should not require value to be set. The resulting SQL should then produce the appropriate OR clause for existence of non-existence after passing the query to the $key_only_queries stack internally.
Adds unit tests. 

Props chrisguitarguy, for the original patch.
Fixes #23268.


Built from https://develop.svn.wordpress.org/trunk@27689


git-svn-id: http://core.svn.wordpress.org/trunk@27528 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-24 19:57:15 +00:00
Andrew Nacin
0e2a70e8f5 Return false from metadata_exists() if the get_$type_metadata filter returns a false value.
props xknown.
fixes #22746.

Built from https://develop.svn.wordpress.org/trunk@27562


git-svn-id: http://core.svn.wordpress.org/trunk@27405 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-17 19:40:16 +00:00
Sergey Biryukov
ab8847316c Correct return values for update_metadata() and related functions.
fixes #21864.
Built from https://develop.svn.wordpress.org/trunk@27191


git-svn-id: http://core.svn.wordpress.org/trunk@27050 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-02-18 21:36:14 +00:00
Scott Taylor
05b22769e9 In update_meta_cache(), ensure that meta is always stored in the same order. Removes an unnecessary $wpdb->prepare statement. Adds unit test.
Props mattheu.
Fixes #25511.


Built from https://develop.svn.wordpress.org/trunk@26307


git-svn-id: http://core.svn.wordpress.org/trunk@26211 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-21 19:31:10 +00:00
Scott Taylor
53a2c3a181 Produce proper CAST for DECIMAL and NUMERIC in Meta Query. Adds a bunch of unit tests.
Props ericlewis.
Fixes #23033.


Built from https://develop.svn.wordpress.org/trunk@26055


git-svn-id: http://core.svn.wordpress.org/trunk@25980 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-08 23:11:08 +00:00
Scott Taylor
5129b9d0ff Respect the compare operator value in meta_query when value evaluates to null. Adds Unit Test.
Props bradyvercher, gradyetc.
Fixes #22967.


Built from https://develop.svn.wordpress.org/trunk@26053


git-svn-id: http://core.svn.wordpress.org/trunk@25978 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-08 22:52:08 +00:00
Andrew Nacin
4ea86c6b47 Return false in update_metadata() and update_metadata_by_mid() when the DB query fails.
props leewillis77.
fixes #24933.

Built from https://develop.svn.wordpress.org/trunk@25583


git-svn-id: http://core.svn.wordpress.org/trunk@25500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-09-23 20:31:09 +00:00
Andrew Nacin
d814ad50b3 Add REGEXP to meta queries.
"REGEXP is usually a terrible idea to use, but I see no reason to disallow it."

props wonderboymusic.
fixes #18736.

Built from https://develop.svn.wordpress.org/trunk@25525


git-svn-id: http://core.svn.wordpress.org/trunk@25445 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-09-20 20:13:09 +00:00
Scott Taylor
8038d7f9e8 Move get_meta_type() into the WP_Meta_Query class as get_cast_for_type(). WP_Query can then access it like: $this->meta_query->get_cast_for_type().
See #21621, [25255].


Built from https://develop.svn.wordpress.org/trunk@25269


git-svn-id: http://core.svn.wordpress.org/trunk@25235 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-09-05 23:32:09 +00:00
Scott Taylor
4be84bbdfb When meta_type is passed with orderby => meta_value, orderby must also use CAST() to avoid scenarios like: SELECTing by UNSIGNED and then ordering by CHAR. Adds unit test.
Fixes #21621.

Built from https://develop.svn.wordpress.org/trunk@25255


git-svn-id: http://core.svn.wordpress.org/trunk@25223 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-09-05 16:57:08 +00:00
Scott Taylor
a9dc60c9a8 Improve inline docs for function params that can be serialized when non-scalar. Fixes #18488.
Built from https://develop.svn.wordpress.org/trunk@25076


git-svn-id: http://core.svn.wordpress.org/trunk@25061 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-08-21 21:11:09 +00:00
Andrew Nacin
4fd4d4452f Use sanitize_key() instead of esc_sql() when 'escaping' variable DB field names. see #21767.
git-svn-id: http://core.svn.wordpress.org/trunk@24714 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-07-16 14:21:05 +00:00
Sergey Biryukov
6c89e06a2a Avoid an undefined index notice. props DrewAPicture. fixes #22096.
git-svn-id: http://core.svn.wordpress.org/trunk@24580 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-07-08 01:49:13 +00:00
Mark Jaquith
24ac7c4ac5 Prevent invalid queries in certain empty-array-passing meta_query cases.
fixes #22096. props wonderboymusic.

git-svn-id: http://core.svn.wordpress.org/trunk@24563 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-07-05 16:40:46 +00:00
Sergey Biryukov
58c364947f PHPDoc fixes and additions. fixes #24616.
git-svn-id: http://core.svn.wordpress.org/trunk@24490 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-06-21 12:45:11 +00:00
Ryan Boren
15a06a35ab Use wp_unslash() instead of stripslashes() and stripslashes_deep(). Use wp_slash() instead of add_magic_quotes().
see #WP21767


git-svn-id: http://core.svn.wordpress.org/trunk@23591 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-03-03 16:30:38 +00:00
Ryan Boren
43a7e695e9 Revert 23416, 23419, 23445 except for wp_reset_vars() changes. We are going a different direction with the slashing cleanup, so resetting to a clean slate. see #21767
git-svn-id: http://core.svn.wordpress.org/trunk@23554 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-03-01 16:28:40 +00:00