From 523b51a3593a496af36f8bfcaa661250821f1350 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 22 Aug 2015 16:59:26 +0000 Subject: [PATCH] Query: 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. Built from https://develop.svn.wordpress.org/trunk@33706 git-svn-id: http://core.svn.wordpress.org/trunk@33673 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp.php | 2 +- wp-includes/query.php | 7 +++++++ wp-includes/version.php | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php index 69a45ada48..062240e221 100644 --- a/wp-includes/class-wp.php +++ b/wp-includes/class-wp.php @@ -15,7 +15,7 @@ class WP { * @access public * @var array */ - public $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type'); + public $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type', 'title'); /** * Private query variables. diff --git a/wp-includes/query.php b/wp-includes/query.php index 916913d1ce..fff57c25bf 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -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'] ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 6a3efdb356..baddfee8ad 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-33705'; +$wp_version = '4.4-alpha-33706'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.