Optimal code for two add_rewrite_rule’s

This is the working code: add_action(‘init’, ‘rewrite_init’); // Rewrite add_action(‘query_vars’, ‘rewrite_query_vars’); add_filter(‘template_include’, ‘rewrite_template_include’); function rewrite_init(){ add_rewrite_rule(‘([^/]+)/([0-9]+)/?$’, ‘index.php?catname=$matches[1]&currentpage=$matches[2]’, ‘top’); add_rewrite_rule(‘cam/([^/]+)/?$’, ‘index.php?name=cam&perf=$matches[1]’, ‘top’); } function rewrite_query_vars($query_vars){ $query_vars[] = ‘currentpage’; $query_vars[] = ‘catname’; $query_vars[] = ‘perf’; return $query_vars; } function rewrite_template_include($template){ if(get_query_var(‘currentpage’) || get_query_var(‘catname’)){ $template = locate_template(array(‘category.php’)); } elseif(get_query_var(‘perf’)){ $template = locate_template(array(‘single.php’)); } return $template; }

Rewrite rule for a query string

Try this code: function geotags_add_rewrite_rules($wp_rewrite_rules) { global $wp_rewrite; $rule_key = ‘%cityid%’; $url_pattern = ‘([^/]+)’; $query_string = ‘cityid=’; $wp_rewrite->add_rewrite_tag($rule_key, $url_pattern, $query_string); $url_structure = $wp_rewrite->root . “cityid/$rule_key/”; $rewrite_rules = $wp_rewrite->generate_rewrite_rules($url_structure); $wp_rewrite_rules = $rewrite_rules + $wp_rewrite_rules; return $wp_rewrite_rules; } add_filter(‘rewrite_rules_array’, ‘geotags_add_rewrite_rules’); function geotags_add_query_var($query_vars) { array_push($query_vars, ‘cityid’); return $query_vars; } add_filter(‘query_vars’,’geotags_add_query_var’); NOTE: Remember to save permalinks so your new … Read more

Need to add rewrite rule that adds in additional information about the post to url

Sorry I took so long to write this up. Hope it’s still useful. This is based off of a tutorial found here and some general playing around. <?php //This function sets up the permastructure add_action(‘init’, ‘setup_permastruct’, 40); function setup_permastruct() { //Setup query vars add_rewrite_tag(‘%state%’,'([^/]+)’); add_rewrite_tag(‘%suburb%’,'([^/]+)’); //Permastruct for custom post type add_permastruct(‘venue’, ‘venue/%state%/%suburb%/%postname%’, false); } //This … Read more

.htaccess rewrite

It looks like you need to process the rewrite using query strings rather than a URI segment and pass your query through index.php. WordPress seems to be agnostic of what you’re trying to accomplish here. Try the following rule and visit your Settings->Permalinks page to flush previous rules and add this to the stack. add_rewrite_rule( … Read more

Monkey Man Rewrite Analyzer says my rule will trigger but it doesn’t [closed]

Honestly, can not debug your code, but this one works: function register_crr_jsonwebservice( $wp_rewrite ) { //Add the rewrite rule for this specific json controller add_rewrite_tag( ‘%ticket%’, ‘([a-zA-Z0-9]+)’); $wp_rewrite->rules = array( ‘cjson/fullticket/?([a-zA-Z0-9]{1,})/?$’ => $wp_rewrite->index . “?page_id=243&ticket=”.$matches[1] ) + $wp_rewrite->rules; } add_action( ‘generate_rewrite_rules’, ‘register_crr_jsonwebservice’ ); Do not call flush_rewrite_rules(); from this function – will lead to an … Read more

WordPress Rewrites – How can I pass a variable to Custom Post Type?

You can use add_rewrite_endpoint, which will add a query var and generate the necessary rewrite rules: function wpd_cid_endpoint() { add_rewrite_endpoint( ‘cid’, EP_PERMALINK ); } add_action( ‘init’, ‘wpd_cid_endpoint’ ); Don’t forget to flush rewrite rules after changing rules. You can do this quickly by visiting the Settings > Permalinks page in admin.

Display posts from Custom Post Type in category page on front-end

You are better off separating categories for posts and using custom taxonomy types for CPT categories. You’d add this line to your register cpt code ‘taxonomies’ => array( ‘bizdirectory-type’ ), Replacing this line in your code. ‘taxonomies’ => array( ‘category’ ), And then add this code in your functions.php add_action( ‘init’, ‘wpsites_custom_taxonomy_types’ ); function wpsites_custom_taxonomy_types() … Read more

WP is ignoring .htaccess rewritten URL

RewriteCond %{HTTP_HOST} dom1 [NC] RewriteRule ^((about\-us|etc).*) /dom1/$1 [NC,QSA,L] Your rewrite rule includes the L parameter, which makes it stop processing rewrites. So WordPress’s rules to redirect to index.php likely never come into effect. Which means WordPress is not even being run here. The 404 is likely from the webserver saying that the file at /dom1/about-us … Read more