Add a query var, `title`, that allows you to query posts by `post_title`. To accomplish this now, you have to do something like:

{{{
$tacos = get_posts( [
  'post_type' => 'taco',
  's' => $name,
  'exact' => true,
  'sentence' => true,
  'post_status' => 'publish',
  'fields' => 'ids',
  'posts_per_page' => 1
] );
}}}

Adds unit tests.

Fixes #33074.


git-svn-id: https://develop.svn.wordpress.org/trunk@33706 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-08-22 16:58:21 +00:00
parent a70e0183e5
commit dc48f3d795
3 changed files with 23 additions and 1 deletions

View File

@@ -1425,6 +1425,7 @@ class WP_Query {
, 'preview'
, 's'
, 'sentence'
, 'title'
, 'fields'
, 'menu_order'
);
@@ -1544,6 +1545,7 @@ class WP_Query {
* true. Note: a string of comma-separated IDs will NOT work.
* @type array $tax_query An associative array of WP_Tax_Query arguments.
* {@see WP_Tax_Query->queries}
* @type string $title Post title.
* @type bool $update_post_meta_cache Whether to update the post meta cache. Default true.
* @type bool $update_post_term_cache Whether to update the post term cache. Default true.
* @type int $w The week number of the year. Default empty. Accepts numbers 0-53.
@@ -1577,6 +1579,7 @@ class WP_Query {
$qv['author'] = preg_replace( '|[^0-9,-]|', '', $qv['author'] ); // comma separated list of positive or negative integers
$qv['pagename'] = trim( $qv['pagename'] );
$qv['name'] = trim( $qv['name'] );
$qv['title'] = trim( $qv['title'] );
if ( '' !== $qv['hour'] ) $qv['hour'] = absint($qv['hour']);
if ( '' !== $qv['minute'] ) $qv['minute'] = absint($qv['minute']);
if ( '' !== $qv['second'] ) $qv['second'] = absint($qv['second']);
@@ -2605,6 +2608,10 @@ class WP_Query {
unset($ptype_obj);
}
if ( '' !== $q['title'] ) {
$where .= $wpdb->prepare( " AND $wpdb->posts.post_title = %s", stripslashes( $q['title'] ) );
}
// Parameters related to 'post_name'.
if ( '' != $q['name'] ) {
$q['name'] = sanitize_title_for_query( $q['name'] );