_find_post_by_old_slug
函数
      _find_post_by_old_slug ( $post_type )    - Access
- Private
- 参数
- 
- 
                (string)
 $post_type
 The current post type based on the query vars.- Required: 是
 
 
- 
                (string)
- 返回值
- 
- (int) The Post ID.
 
- 相关
- 
- wp_old_slug_redirect()
 
- 定义位置
- 
- 
                                  wp-includes/query.php
 , line 1136
 
- 
                                  wp-includes/query.php
- 引入
- 4.9.3
- 弃用
- –
找到重定向一个旧slug的文章ID。
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' ) );
	}
	$key          = md5( $query );
	$last_changed = wp_cache_get_last_changed( 'posts' );
	$cache_key    = "find_post_by_old_slug:$key:$last_changed";
	$cache        = wp_cache_get( $cache_key, 'posts' );
	if ( false !== $cache ) {
		$id = $cache;
	} else {
		$id = (int) $wpdb->get_var( $query );
		wp_cache_set( $cache_key, $id, 'posts' );
	}
	return $id;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
 
      