WordPress.org

Make WordPress Core

Ticket #33065: add_name_array.patch

File add_name_array.patch, 1.8 KB (added by enshrined, 6 years ago)

This adds the ability to pass a post_namein array to WP_Query for filtering

  • wp-includes/query.php

     
    14341434                                $array[$key] = '';
    14351435                }
    14361436
    1437                 $array_keys = array( 'category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in',
     1437                $array_keys = array( 'category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', 'post_name__in',
    14381438                        'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'post_parent__in', 'post_parent__not_in',
    14391439                        'author__in', 'author__not_in' );
    14401440
     
    15261526         *     @type string|array $post_status             A post status (string) or array of post statuses.
    15271527         *     @type int          $posts_per_page          The number of posts to query for. Use -1 to request all posts.
    15281528         *     @type int          $posts_per_archive_page  The number of posts to query for by archive page. Overrides
     1529         *     @type array        $post_name__in           An array of post slugs to retrieve, sticky posts will be included
    15291530         *                                                 'posts_per_page' when is_archive(), or is_search() are true.
    15301531         *     @type string       $s                       Search keyword.
    15311532         *     @type int          $second                  Second of the minute. Default empty. Accepts numbers 0-60.
     
    26902691                        $search = $this->parse_search( $q );
    26912692                }
    26922693
     2694                // If a post name array is supplied, filter on it
     2695                if ( isset( $q['post_name__in'] ) && is_array( $q['post_name__in'] ) && count( $q['post_name__in'] ) > 0) {
     2696                        array_map( 'sanitize_title_for_query', $q['post_name__in'] );
     2697                        $where .= " AND $wpdb->posts.post_name IN('" . implode("' ,'", $q['post_name__in']) . "')";
     2698                }
     2699
    26932700                /**
    26942701                 * Filter the search SQL that is used in the WHERE clause of WP_Query.
    26952702                 *