找到重定向旧slug的帖子ID。

原型

_find_post_by_old_slug( string $post_type )

参数

$post_type (string) (Required) 基于查询变量的当前帖子类型。

返回值

(int)  $ id帖子ID。

源文件

路径:wp-includes/query.php

<?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;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/_find_post_by_old_slug/