简体   繁体   中英

Wordpress Permalinks as GET vars from a custom page template (only numbers)

I'm trying to add a rewrite rule to pass a var to my page template.

it only excepts numbers in the variables, when I type in characters other then number it directs to 404. for example: this works: domain.com/reco/9080 But this doesn't: domain.com/reco/abcd (redirects to 404)

This is my code:

function add_rewrite_rules($wp_rewrite) {
        add_rewrite_rule('reco/([^/]*)/?', 'index.php/reco/?b=$1', 'top');
}
add_action('generate_rewrite_rules', 'add_rewrite_rules');


function query_vars($public_query_vars) {
    $public_query_vars[] = "b";
    return $public_query_vars;
}
add_filter('query_vars', 'query_vars');

Cheers!

I ended up using get_query_var('b') which works! apparently wordpress "hogs" the query vars because the website is actually: index.php?pagename=yourPermalink .

Also don't try to use variable "s" because wordpress uses this on every page for search purposes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM