diff --git a/src/wp-includes/canonical.php b/src/wp-includes/canonical.php
index 6a74ac2d43..167b5cf562 100644
|
a
|
b
|
function redirect_guess_404_permalink() { |
| 895 | 895 | |
| 896 | 896 | // If any of post_type, year, monthnum, or day are set, use them to refine the query. |
| 897 | 897 | if ( get_query_var( 'post_type' ) ) { |
| 898 | | $where .= $wpdb->prepare( ' AND post_type = %s', get_query_var( 'post_type' ) ); |
| | 898 | if ( is_array( get_query_var( 'post_type' ) ) ) { |
| | 899 | // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare |
| | 900 | $where .= " AND post_type IN ('" . join( "', '", esc_sql( get_query_var( 'post_type' ) ) ) . "')"; |
| | 901 | } else { |
| | 902 | $where .= $wpdb->prepare( ' AND post_type = %s', get_query_var( 'post_type' ) ); |
| | 903 | } |
| 899 | 904 | } else { |
| 900 | 905 | $where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true ) ) ) . "')"; |
| 901 | 906 | } |
diff --git a/tests/phpunit/tests/canonical.php b/tests/phpunit/tests/canonical.php
index 895e5bb44e..bd0b68c038 100644
|
a
|
b
|
public function test_strict_redirect_guess_404_permalink() { |
| 275 | 275 | $this->assertFalse( redirect_guess_404_permalink() ); |
| 276 | 276 | } |
| 277 | 277 | |
| | 278 | /** |
| | 279 | * Ensure multiple post types do not throw a notice. |
| | 280 | * |
| | 281 | * @ticket 43056 |
| | 282 | */ |
| | 283 | public function test_redirect_guess_404_permalink_post_types() { |
| | 284 | /* |
| | 285 | * Sample-page is intentionally missspelt as sample-pag to ensure |
| | 286 | * the 404 post permalink guessing runs. |
| | 287 | * |
| | 288 | * Please do not correct the apparent typo. |
| | 289 | */ |
| | 290 | |
| | 291 | // String format post type. |
| | 292 | $this->assertCanonical( '/?name=sample-pag&post_type=page', '/sample-page/' ); |
| | 293 | // Array formatted post type or types. |
| | 294 | $this->assertCanonical( '/?name=sample-pag&post_type[]=page', '/sample-page/' ); |
| | 295 | $this->assertCanonical( '/?name=sample-pag&post_type[]=page&post_type[]=post', '/sample-page/' ); |
| | 296 | } |
| | 297 | |
| 278 | 298 | /** |
| 279 | 299 | * @ticket 43745 |
| 280 | 300 | */ |