Make WordPress Core

Ticket #38709: core.2.patch

File core.2.patch, 938 bytes (added by Khadreal, 7 months ago)

The patch suggested by @rebasaurus remove the query but doesn't resolve the issue as draft post still shows up. I set is_singular to false when the query name is empty and it's singular and not a preview. PS. My last two comments were mistake and I couldn't delete

  • src/wp-includes/class-wp-query.php

    diff --git forkSrcPrefix/src/wp-includes/class-wp-query.php forkDstPrefix/src/wp-includes/class-wp-query.php
    index f683a52bd108011148b2c76c23dcc78bffc57067..373d677a1cf434f33b5099da697df06e43bfe505 100644
    old new class WP_Query { 
    21342134                        $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title = %s", stripslashes( $q['title'] ) );
    21352135                }
    21362136
     2137                // Set is_singular to false.
     2138                if( '' === sanitize_title_for_query( $q['name'] ) && true === $this->is_singular && ! $this->is_preview ){
     2139                        $this->is_singular = false;
     2140                }
     2141
    21372142                // Parameters related to 'post_name'.
    2138                 if ( '' !== $q['name'] ) {
     2143                if ( '' !== sanitize_title_for_query( $q['name'] ) ) {
    21392144                        $q['name'] = sanitize_title_for_query( $q['name'] );
    21402145                        $where    .= " AND {$wpdb->posts}.post_name = '" . $q['name'] . "'";
    21412146                } elseif ( '' !== $q['pagename'] ) {