返回介绍

redirect_guess_404_permalink()

发布于 2017-09-11 10:04:07 字数 2886 浏览 1007 评论 0 收藏 0

redirect_guess_404_permalink()

Attempts to guess the correct URL based on query vars


description


返回值

(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;
}

更新日志

Versiondescription
2.3.0Introduced.

相关函数

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文