redirect_guess_404_permalink() - WordPress 函数参考中文文档

返回介绍

redirect_guess_404_permalink()

发布于 2017-09-11 字数2886 浏览 902 评论 0

redirect_guess_404_permalink()

Attempts to guess the correct URL based on query vars


描述


返回值

(false|string) The correct URL if one is found. False on failure.


源代码

File: wp-includes/canonical.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;
}

更新日志

Version 描述
2.3.0 Introduced.

相关函数

Uses

  • wp-includes/wp-db.php:
    wpdb::esc_like()
  • wp-includes/formatting.php:
    trailingslashit()
  • wp-includes/query.php:
    get_query_var()
  • wp-includes/link-template.php:
    get_post_comments_feed_link()
  • wp-includes/link-template.php:
    get_permalink()
  • wp-includes/link-template.php:
    user_trailingslashit()
  • wp-includes/post.php:
    get_post_types()
  • wp-includes/wp-db.php:
    wpdb::get_var()
  • wp-includes/wp-db.php:
    wpdb::prepare()
  • Show 4 more uses
    Hide more uses


Used By

  • wp-includes/canonical.php:
    redirect_canonical()

User Contributed Notes

上一篇:redirect_canonical()

下一篇:redirect_post()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!