Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




redirect_guess_404_permalink [ WordPress Function ]

redirect_guess_404_permalink ( $current_url = '' )
Parameters:
  • (string) $current_url Optional. The URL that has 404'd.
Uses:
  • $wpdb
Returns:
  • (bool|string) The correct URL if one is found. False on failure.
Defined at:



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_escapeget_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_idget_query_var'feed' ) );
        elseif ( 
get_query_var'page' ) )
            return 
trailingslashitget_permalink$post_id ) ) . user_trailingslashitget_query_var'page' ), 'single_paged' );
        else
            return 
get_permalink$post_id );
    }

    return 
false;
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

Kullanýcý Tartýþmalarý [ wordpress.org ]

- Bulunamadý -

Yeni bir konu yaz ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics