[wp-trac] [WordPress Trac] #34373: Don't set is_home=>true in WP_Query during REST request

WordPress Trac noreply at wordpress.org
Wed Nov 18 18:15:19 UTC 2015


#34373: Don't set is_home=>true in WP_Query during REST request
--------------------------------------+------------------
 Reporter:  danielbachhuber           |       Owner:
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  4.4
Component:  REST API                  |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  dev-feedback needs-patch  |     Focuses:
--------------------------------------+------------------

Comment (by danielbachhuber):

 I started working on a patch to set `WP_Query::$is_rest`, and got stuck on
 how the the parameter should actually be set.

 In the main query, we can check for `rest_route`. If it's not empty, it
 would sensibly define `is_rest`. However, the main query isn't very useful
 a request to `/wp-json/`.

 As a developer, if I need to make use of `WP_Query` within my endpoint
 callback, I'll instantiate a new `WP_Query`, which won't have a
 `rest_route` argument (typically).

 If I want to only hook into `pre_get_posts` or similar, I ''could'' check
 `defined( 'REST_REQUEST' )`. But, this constant is defined in
 `rest_api_loaded`, which may not have executed fully if I'm calling the
 REST API from some alternative context.

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


More information about the wp-trac mailing list