permalinks - Custom optional parameter in page URL

I'm losing my mind, so I do hope I can get some help here..What I'm trying to do is to create an optional para

I'm losing my mind, so I do hope I can get some help here..

What I'm trying to do is to create an optional parameter for search page, just for the sake of SEO

For example, there are the options:

/search/ (category = null)

/search/contracts (category = contracts)

/search/.../ (category = whatever this parameter $1 is)

While search is a page

I've tried adding htaccess rewrite rule, and wordpress simply redirected 301 without passing the parameter. Then I tried with add_rewrite_endpoint, nothing worked whatsoever and I've tried with

function wpd_add_query_vars( $qvars ) {
  $qvars[] = 'category';
  return $qvars;
}
add_filter( 'query_vars', 'wpd_add_query_vars' );

add_rewrite_rule(
    '^search/([^/]+)/?',
    'index.php?post_id=806&category=$matches[1]',
    'top'
);

add_rewrite_tag('%category%', '([^&]+)');

flush_rewrite_rules();

Do note I tried just about every permutation, also tried plugins, nothing worked. It was either a 404 or the $wp_query->query_vars did not include the parameter.

Thanks in advance..

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745674355a4639595.html

相关推荐

  • permalinks - Custom optional parameter in page URL

    I'm losing my mind, so I do hope I can get some help here..What I'm trying to do is to create an optional para

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信