_find_post_by_old_slug

Advertisement

Private Access Private Access

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use wp_old_slug_redirect() instead.

Summery Summery

Find the post ID for redirecting an old slug.

Syntax Syntax

_find_post_by_old_slug( string $post_type )

Parameters Parameters

$post_type

(string) (Required) The current post type based on the query vars.

Return Return

(int) $id The Post ID.

Source Source

File: wp-includes/query.php

 */
function _find_post_by_old_slug( $post_type ) {
	global $wpdb;

	$query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, get_query_var( 'name' ) );

	// If year, monthnum, or day have been specified, make our query more precise
	// just in case there are multiple identical _wp_old_slug values.
	if ( get_query_var( 'year' ) ) {
		$query .= $wpdb->prepare( ' AND YEAR(post_date) = %d', get_query_var( 'year' ) );
	}
	if ( get_query_var( 'monthnum' ) ) {
		$query .= $wpdb->prepare( ' AND MONTH(post_date) = %d', get_query_var( 'monthnum' ) );
	}
	if ( get_query_var( 'day' ) ) {
		$query .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) );
	}

	$id = (int) $wpdb->get_var( $query );

	return $id;

Advertisement

Changelog Changelog

Changelog
Version Description
4.9.3 Introduced.

See also See also

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.