WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Купить персональные IPV4 и IPV6 прокси
функция не описана

redirect_guess_404_permalink() WP 2.3.0

Attempts to guess the correct URL based on query vars

Хуков нет.

Возвращает

false/Строку. The correct URL if one is found. False on failure.

Использование

redirect_guess_404_permalink();

Заметки

  • Global. wpdb. $wpdb WordPress database abstraction object.

Список изменений

С версии 2.3.0 Введена.

Код redirect guess 404 permalink: wp-includes/canonical.php WP 5.2.2

<?php
function redirect_guess_404_permalink() {
	global $wpdb;

	if ( get_query_var( 'name' ) ) {
		$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' ) ) {
			$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' ) );
		}

		$post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'" );
		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 < get_query_var( 'page' ) ) {
			return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
		} else {
			return get_permalink( $post_id );
		}
	}

	return false;
}