redirect_guess_404_permalink(): string|false  Attempts to guess the correct URL for a 404 request based on query vars.   Return string|false The correct URL if one is found. False on failure.   Source  File: wp-includes/canonical.php. View all references  function redirect_guess_404_permalink() {
	global $wpdb;

	/**
	 * Filters whether to attempt to guess a redirect URL for a 404 request.
	 *
	 * Returning a false value from the filter will disable the URL guessing
	 * and return early without performing a redirect.
	 *
	 * @since 5.5.0
	 *
	 * @param bool $do_redirect_guess Whether to attempt to guess a redirect URL
	 *                                for a 404 request. Default true.
	 */
	if ( false === apply_filters( 'do_redirect_guess_404_permalink', true ) ) {
		return false;
	}

	/**
	 * Short-circuits the redirect URL guessing for 404 requests.
	 *
	 * Returning a non-null value from the filter will effectively short-circuit
	 * the URL guessing, returning the passed value instead.
	 *
	 * @since 5.5.0
	 *
	 * @param null|string|false $pre Whether to short-circuit guessing the redirect for a 404.
	 *                               Default null to continue with the URL guessing.
	 */
	$pre = apply_filters( 'pre_redirect_guess_404_permalink', null );
	if ( null !== $pre ) {
		return $pre;
	}

	if ( get_query_var( 'name' ) ) {
		/**
		 * Filters whether to perform a strict guess for a 404 redirect.
		 *
		 * Returning a truthy value from the filter will redirect only exact post_name matches.
		 *
		 * @since 5.5.0
		 *
		 * @param bool $strict_guess Whether to perform a strict guess. Default false (loose guess).
		 */
		$strict_guess = apply_filters( 'strict_redirect_guess_404_permalink', false );

		if ( $strict_guess ) {
			$where = $wpdb->prepare( 'post_name = %s', get_query_var( 'name' ) );
		} else {
			$where = $wpdb->prepare( 'post_name LIKE %s', $wpdb->esc_like( get_query_var( 'name' ) ) . '%' );
		}

		// If any of post_type, year, monthnum, or day are set, use them to refine the query.
		if ( get_query_var( 'post_type' ) ) {
			if ( is_array( get_query_var( 'post_type' ) ) ) {
				// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
				$where .= " AND post_type IN ('" . join( "', '", esc_sql( get_query_var( 'post_type' ) ) ) . "')";
			} else {
				$where .= $wpdb->prepare( ' AND post_type = %s', get_query_var( 'post_type' ) );
			}
		} else {
			$where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true ) ) ) . "')";
		}

		if ( get_query_var( 'year' ) ) {
			$where .= $wpdb->prepare( ' AND YEAR(post_date) = %d', get_query_var( 'year' ) );
		}
		if ( get_query_var( 'monthnum' ) ) {
			$where .= $wpdb->prepare( ' AND MONTH(post_date) = %d', get_query_var( 'monthnum' ) );
		}
		if ( get_query_var( 'day' ) ) {
			$where .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) );
		}

		$publicly_viewable_statuses = array_filter( get_post_stati(), 'is_post_status_viewable' );
		// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
		$post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status IN ('" . implode( "', '", esc_sql( $publicly_viewable_statuses ) ) . "')" );

		if ( ! $post_id ) {
			return false;
		}

		if ( get_query_var( 'feed' ) ) {
			return get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) );
		} elseif ( get_query_var( 'page' ) > 1 ) {
			return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
		} else {
			return get_permalink( $post_id );
		}
	}

	return false;
}
   Hooks     apply_filters( 'do_redirect_guess_404_permalink', bool $do_redirect_guess )   
Filters whether to attempt to guess a redirect URL for a 404 request.      apply_filters( 'pre_redirect_guess_404_permalink', null|string|false $pre )   
Short-circuits the redirect URL guessing for 404 requests.      apply_filters( 'strict_redirect_guess_404_permalink', bool $strict_guess )   
Filters whether to perform a strict guess for a 404 redirect.      Related  Uses    Uses Description      wp8b7c:f320:99b9:690f:4595:cd17:293a:c069esc_like() wp-includes/class-wpdb.php   First half of escaping for LIKE special characters % and _ before preparing for SQL.     esc_sql() wp-includes/formatting.php   Escapes data for use in a MySQL query.     get_query_var() wp-includes/query.php   Retrieves the value of a query variable in the WP_Query class.     get_post_comments_feed_link() wp-includes/link-template.php   Retrieves the permalink for the post comments feed.     user_trailingslashit() wp-includes/link-template.php   Retrieves a trailing-slashed string if the site is set for adding trailing slashes.     get_post_stati() wp-includes/post.php   Gets a list of post statuses.     trailingslashit() wp-includes/formatting.php   Appends a trailing slash.     get_permalink() wp-includes/link-template.php   Retrieves the full permalink for the current post or post ID.     apply_filters() wp-includes/plugin.php   Calls the callback functions that have been added to a filter hook.     get_post_types() wp-includes/post.php   Gets a list of all registered post type objects.     wp8b7c:f320:99b9:690f:4595:cd17:293a:c069get_var() wp-includes/class-wpdb.php   Retrieves one variable from the database.     wp8b7c:f320:99b9:690f:4595:cd17:293a:c069prepare() wp-includes/class-wpdb.php   Prepares a SQL query for safe execution.   
   Used By    Used By Description      redirect_canonical() wp-includes/canonical.php   Redirects incoming links to the proper URL based on the site url.   
    Changelog    Version Description     2.3.0 Introduced.    

    
{'path': 'public/docs/wordpress/functions/redirect_guess_404_permalink.html', 'source': 'DevDocs.IO'}