admin管理员组文章数量:1124556
We have some rewrite rules and would like to get the url parameters on that pages/feeds.
That does work on regular feeds, but not on those with a rewrite rule.
On regular feeds like /?somevalue=xyz
I can use get_query_var('somevalue')
and it results in xyz
.
On rewritten pages like /?somevalue=xyz
it is just empty.
We have first defined the query vars:
function add_get_val() {
global $wp;
$wp->add_query_var('somevalue');
}
add_action('init','add_get_val');
Then we did this rewrite rule:
function custom_rewrite_rule() {
add_rewrite_rule('^rewrittenpage/([^/]+)/feed/?', 'index.php?custom_name=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_rule');
And did define this query var:
function custom_query_var($query_vars) {
$query_vars[] = 'custom_name';
return $query_vars;
}
add_filter('query_vars', 'custom_query_var');
Last we redirected to the feed template with a query:
function custom_template_redirect() {
global $wp_query;
$custom_name = get_query_var('custom_name');
if ($custom_name) {
$wp_query = new WP_Query(array(
'meta_query' => array(
array(
'key' => '_custom',
'value' => $custom_name,
'compare' => '=',
),
),
));
load_template( STYLESHEETPATH . '/feed-rss2.php');
}
}
add_action('template_redirect', 'custom_template_redirect');
This works totally fine. But as already described: When I want to get my query vars (like somevalue
) within the template on that rewritten feed, get_query_var('somevalue')
is always empty.
How can I access any query vars within that rewritten template?
本文标签: queryGet URL parameters with rewrite rules
版权声明:本文标题:query - Get URL parameters with rewrite rules 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736635448a1945867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论