[wp-trac] [WordPress Trac] #62646: PHP Warning in REST API when post_type doesn't support post-formats, but a post-format filter is applied.

WordPress Trac noreply at wordpress.org
Thu Dec 5 03:39:08 UTC 2024


#62646: PHP Warning in REST API when post_type doesn't support post-formats, but a
post-format filter is applied.
--------------------------+------------------------------
 Reporter:  dd32          |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  REST API      |     Version:  6.7
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by dd32):

 One way to resolve this, one could check the post_type supports post-
 formats before adding it to the query:
 {{{#!diff
 Index: wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
 ===================================================================
 --- wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
 (revision 58872)
 +++ wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
 (working copy)
 @@ -346,7 +346,7 @@

                 $args = $this->prepare_tax_query( $args, $request );

 -               if ( ! empty( $request['format'] ) ) {
 +               if ( ! empty( $request['format'] ) && post_type_supports(
 $this->post_type, 'post-formats' ) ) {
                         $formats = $request['format'];
                         /*
                          * The relation needs to be set to `OR` since the
 request can contain
 }}}

 However this causes a logic change between 6.7 and post-change;[[BR]]
 Currently querying `https://example.org/wp-json/wp/v2/pt-no-post-
 formats?format[]=standard` will result in no-results (kinda expected,
 since no post-formats in that post type will match). after the change,
 it'll ignore the parameter and return the same results as
 `https://example.org/wp-json/wp/v2/pt-no-post-formats`.

 I think that's likely expected, and would be the same as querying
 `?skajdghadisjvxkhadsijf=true` (assuming that's not a valid query param).

 (cc @peterwilsoncc this is what i mentioned to you)

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


More information about the wp-trac mailing list