[wp-trac] [WordPress Trac] #50506: PHP warning appearing in 404 page and 'post_type' query var is Array

WordPress Trac noreply at wordpress.org
Mon Jun 29 11:34:44 UTC 2020


#50506: PHP warning appearing in 404 page and 'post_type' query var is Array
-------------------------+-----------------------------
 Reporter:  arl1nd       |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  5.4.2
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 Fixed PHP warning appearing in 404 page and 'post_type' field is Array
 (not string), more exactly function: `redirect_guess_404_permalink` line
 700 in '''wp-includes/canonical.php'''

 To replicate this issue simply add this code inside plugin/theme:

 {{{
 function _debug_php_warning_on_404( $query ) {
         $query->set( 'post_type', [ 'post', 'portfolio', 'page' ] );
 }
 add_action( 'pre_get_posts', '_debug_php_warning_on_404' );
 }}}

 Then try a missing page slug __domain.test/missing-content__ it will show
 a warning:


   wpdb::prepare was called incorrectly. The query only expected one
 placeholder, but an array of multiple placeholders was sent. Please see
 Debugging in WordPress for more information. (This message was added in
 version 4.9.0.)

 The fix is to replace line 700 and check for array "post_type" query var:

 {{{
 if ( $post_type = get_query_var( 'post_type' ) ) {
         if ( is_array( $post_type ) ) {
                 $where .= " AND post_type IN ('" . implode( "', '",
 esc_sql( $post_type ) ) . "')";
         } else {
                 $where .= $wpdb->prepare( ' AND post_type = %s',
 $post_type );
         }
 }
 }}}

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


More information about the wp-trac mailing list