[wp-trac] [WordPress Trac] #38629: REST API: Allowed public or private WP_Query vars are lost in `prepare_items_query()`

WordPress Trac noreply at wordpress.org
Fri Nov 4 16:44:48 UTC 2016


#38629: REST API: Allowed public or private WP_Query vars are lost in
`prepare_items_query()`
--------------------------+-----------------------
 Reporter:  rachelbaker   |       Owner:  rmccue
     Type:  defect (bug)  |      Status:  assigned
 Priority:  normal        |   Milestone:  4.7
Component:  REST API      |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+-----------------------

Comment (by joehoyle):

 @danielbachhuber I don't think we should do it in an automatic way, if I
 wanted to add support for a query var, I'd do this:

 {{{#!php
 <?php
 add_action( 'rest_post_collection_params', function( $params ) {
         $params['date_month'] => array(
                 'type'        => 'integer',
                 'description' => 'Restrict posts to ones published in a
 specific month.'
         );
         return $params;
 } );

 add_filter( 'rest_post_query', function( $query_vars, $request ) ) {
         if ( $request['date_month'] ) {
                 $query_vars['month'] = $request['date_month'];
         }
         return $query_vars;
 }, 10, 2 );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38629#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list