admin管理员组文章数量:1122832
I really want to figure this out.
What I want to do, is this URI
.php?page=76&type=hotels&id=1
transform to
Actually 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/item/hotels/1
to my browser it cuts to hotels-lithuania/item/
and of course no items displayed.
Screen from rewrite analyzer plugin: .png
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'];
I really want 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
Actually 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 of course no items displayed.
Screen from rewrite analyzer plugin: https://i.sstatic.net/AgNoq.png
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
edited May 30, 2024 at 6:24
CommunityBot
1
asked Jun 11, 2012 at 17:54
zilvinaszilvinas
11 bronze badge
1
- Screen from rewrite analyzer plugin: i.sstatic.net/AgNoq.png – zilvinas Commented Jun 11, 2012 at 17:58
1 Answer
Reset to default 2I 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
.
本文标签: permalinksProblems with rewrite rule
版权声明:本文标题:permalinks - Problems with rewrite rule 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305682a1932677.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论