I use this simple rule :
add_rewrite_rule(
'^product/([0-9]+)-([^/]+)?$',
'index.php?pagename=product&id=$matches[1]&slug=$matches[2]',
'top'
);
It works, it redirects to the correct page I have created, but I can't get the id param, I tried in the template of my page :
global $wp_query;
// undefined index
var_dump($wp_query->query_vars['id']);
I want my URL to be like this :
Dunno if it's possible ?
I use this simple rule :
add_rewrite_rule(
'^product/([0-9]+)-([^/]+)?$',
'index.php?pagename=product&id=$matches[1]&slug=$matches[2]',
'top'
);
It works, it redirects to the correct page I have created, but I can't get the id param, I tried in the template of my page :
global $wp_query;
// undefined index
var_dump($wp_query->query_vars['id']);
I want my URL to be like this :
http://example/product/324-example-of-slug
Dunno if it's possible ?
Share Improve this question asked Jul 16, 2019 at 8:29 Vincent DecauxVincent Decaux 2252 silver badges12 bronze badges1 Answer
Reset to default 0Ok, you need to add the id
param to the list of public query variables :
add_filter('query_vars', 'query_vars');
function query_vars($public_query_vars)
{
$public_query_vars[] = 'id';
return $public_query_vars;
}
Thanks to this plugin for the help : https://wordpress/plugins/monkeyman-rewrite-analyzer/#reviews
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745318622a4622336.html
评论列表(0条)