Advertisements

redirect_guess_404_permalink

Definition:
function redirect_guess_404_permalink() {}

Attempts to guess correct post based on query vars.

Return values

returns:Returns False, if it can’t find post, returns correct location on success.

Source code

function redirect_guess_404_permalink() {

	global $wpdb;



	if ( !get_query_var('name') )

		return false;



	$where = $wpdb->prepare("post_name LIKE %s", like_escape( 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'));

	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;

	return get_permalink($post_id);

}

2639

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: