_find_post_by_old_slug()
Core function that retrieves the post ID for redirecting from the old url to the new one.
Used in the function wp_old_slug_redirect(), which performs the redirect if the post ID was found.
Algorithm:
-
Creates the basis for the SQL query to find the post ID by the given post type and the specified value in the meta-field with the key
_wp_old_slugequal toget_query_var('name'). -
Adds clarifications to the query based on
get_query_var('year'),get_query_var('monthnum'),get_query_var('day'), if the permalink of the post uses the year, month, day of publication. - Using $wpdb->get_var() makes the query and returns the post ID.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
Int. post ID.
Usage
_find_post_by_old_slug( $post_type );
- $post_type(string) (required)
- The current post type based on query variables.
Examples
#1 An example from the WordPress core
See the code of function wp_old_slug_redirect().
Notes
- See: wp_old_slug_redirect()
- Global. wpdb.
$wpdbWordPress database abstraction object.
Changelog
| Since 4.9.3 | Introduced. |