redirect_guess_404_permalink [ WordPress Function ]
redirect_guess_404_permalink ( $current_url = '' )
| Parameters: |
|
| Uses: |
|
| Returns: |
|
| Defined at: |
|
Benzer Fonksiyonlar: get_post_permalink, get_blog_permalink, get_permalink, the_permalink, get_sample_permalink
Attempts to guess the correct URL from the current URL (that produced a 404) or the current query variables.
Source
<?php
function redirect_guess_404_permalink( $current_url = '' ) {
global $wpdb, $wp_rewrite;
if ( ! empty( $current_url ) )
$parsed_url = @parse_url( $current_url );
// Attempt to redirect bare category slugs if the permalink structure starts
// with the %category% tag.
if ( isset( $parsed_url['path'] )
&& preg_match( '#^[^%]+%category%#', $wp_rewrite->permalink_structure )
&& $cat = get_category_by_path( $parsed_url['path'] )
) {
if ( ! is_wp_error( $cat ) )
return get_term_link( $cat );
}
if ( get_query_var('name') ) {
$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'));
else
$where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true ) ) ) . "')";
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;
if ( get_query_var( 'feed' ) )
return get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) );
elseif ( get_query_var( 'page' ) )
return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
else
return get_permalink( $post_id );
}
return false;
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- #16557 (Ability to disable redirect_guess_404_permalink ...
Can you make redirect_guess_404_permalink() pluggable or have its return value pass-through a filter so ... New filter to replace redirect_guess_404_permalink ...
core.trac.wordpress.org - #19693 (redirect_guess_404_permalink() can catch the wrong post ...
(And while we're at it, we should hook redirect_guess_404_permalink() into redirect_canonical() so it may be unhooked without removing all canonical support.) ...
core.trac.wordpress.org - redirect_guess_404_permalink() WordPress function reference ...
Attempts to guess correct post based on query vars.
queryposts.com - permalinks - How do I turn off 301 redirecting posts (not canonical ...
This appears to have to do with redirect_guess_404_permalink() called on line 96 of wp-includes/canonical.php . Just to test, I added a return false; to the first ...
wordpress.stackexchange.com