[wp-trac] [WordPress Trac] #43056: Notice in redirect_guess_404_permalink() when post type is an array

WordPress Trac noreply at wordpress.org
Wed Jan 10 00:22:33 UTC 2018


#43056: Notice in redirect_guess_404_permalink() when post type is an array
--------------------------+-----------------------------
 Reporter:  junaidbhura   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Canonical     |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When manipulating URLs, it sometimes becomes necessary to update the query
 using the `pre_get_posts` hook.

 If we set the post type to an array in the `pre_get_posts` hook like so:


 {{{
 $query->set( 'post_type', array( 'post', 'page', 'my_cpt' ) );
 }}}


 On a 404 page, we get a notice when `WP_DEBUG` is set to `true`:

 '''Notice: wpdb::prepare was called incorrectly. The query only expected
 one placeholder, but an array of multiple placeholders was sent.'''

 This is caused by the following code in `redirect_guess_404_permalink()`:


 {{{
 $where .= $wpdb->prepare(" AND post_type = %s",
 get_query_var('post_type'));
 }}}

 This can be fixed by looking for an array and updating the query.

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


More information about the wp-trac mailing list