Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I realy cant to figure this out.

What i want to do, is this URI http://www.hotels-lithuania.net/index.php?page=76&type=hotels&id=1 transform to http://www.hotels-lithuania.net/item/hotels/1. Actualy i have read tons of pages, what i come to is this:

add_action( 'init', 'wpa5413_init' );
function wpa5413_init()
{
    add_rewrite_rule(
        'item/([^/]+)/([^/]+)?',
        'index.php?page=76&type=$matches[1]&id=$matches[2]',
        'top' );
}
add_filter( 'query_vars', 'wpa5413_query_vars' );
function wpa5413_query_vars( $query_vars )
{
    $query_vars[] = 'type';
    $query_vars[] = 'id';
    return $query_vars;
}

If I enter hotels-lithuania.net/item/hotels/1 to my browser it cuts to hotels-lithuania.net/item/ and ofc no items displayed.

Screen from rewrite analyzer plugin: i.stack.imgur.com/AgNoq.png

Sorry for bad hyperlinks, but i am new here and can't post ir proper

EDIT: I dont know why, but i had guid in my db with value localhost/hotel/?page_id=76 So my final rewrite_rule looks like this:

add_action( 'init', 'wpa5413_init' );
function wpa5413_init()
{
    add_rewrite_rule(
        'item/([^/]+)/([^/]+)?',
        'index.php?page_id=76&itemType=$matches[1]&itemId=$matches[2]',
        'top' );
}
add_filter( 'query_vars', 'wpa5413_query_vars' );
function wpa5413_query_vars( $query_vars )
{
    $query_vars[] = 'itemType';
    $query_vars[] = 'itemId';
    return $query_vars;
}

And using these variables with:

global $wp;
$type = $wp->query_vars['itemType'];
$id = $wp->query_vars['itemId'];
share|improve this question
    
Screen from rewrite analyzer plugin: i.stack.imgur.com/AgNoq.png –  zilvinas Jun 11 '12 at 17:58
add comment

1 Answer

I suspect you have a conflict with your query vars. id is already a WordPress query var, and type is a reserved word. You should use vars that you know will be unique among core and any plugin you may use by prefixing everything, like zilvinas_id and zilvinas_type.

share|improve this answer
    
Thank you for your answer. I tryed your sollution, but still no good. If i try hotels-lithuania.net/item/hotel/1 it cuts my variables. i48.tinypic.com/2zoc1ad.png –  zilvinas Jun 11 '12 at 22:09
    
Are you resaving your permalinks after you modify the rewrites function? –  Pippin Jun 11 '12 at 22:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.