[wp-trac] [WordPress Trac] #33065: Allow for querying by `post_name__in`

WordPress Trac noreply at wordpress.org
Wed Jul 22 01:38:16 UTC 2015


#33065: Allow for querying by `post_name__in`
-------------------------+-----------------------------
 Reporter:  dd32         |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Query        |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 When implementing WP_Query with external data-sources, I'm finding a
 common theme to being wanting to query by a selection of post slugs
 retrieved from an external system.

 WordPress currently utilises `post_id__in` for sticky posts, and some
 plugins use the same query var. However, when you're integrating with
 another system which doesn't use WordPress post id's, the post slug is the
 most obvious field to use as the shared key.

 For example, I'd love to be able to do this query:
 {{{
 $query = new WP_Query(
    'post_type' => 'post',
    'post_name__in' => array( 'sample-post', 'my-post', 'secret-projects'
 ),
    'meta_query' => array( ... ),
    'tax_query'  => array( ... ),
    'date_query' => array( ... ),
 );
 }}}

 Right now, there's three main workarounds
 1. Store post ID's along side the post_name
 2. Retrieve all post ID's for the slugs, then pass those in as
 `post_id__in`
 3. Using the `posts_clauses` filter to add a `AND post_name IN(...)` where
 clause.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33065>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list