How to properly rewrite url by custom var

I’ve been trying to rewrite a shop uri, and what I have now is this code: add_filter(‘rewrite_rules_array’,’wp_insertMyRewriteRules’); add_filter(‘query_vars’,’wp_insertMyRewriteQueryVars’); add_filter(‘wp_loaded’,’flushRules’); // Remember to flush_rules() when adding rules function flushRules(){ global $wp_rewrite; $wp_rewrite->flush_rules(); } // Adding a new rule function wp_insertMyRewriteRules($rules) { $newrules = array(); $newrules[‘shop/brand/(brand)/?$’] = ‘shop.php?brand=$matches[1]’ ; //$wp_rewrite->rules = $new_rules + $wp_rewrite->rules; return $newrules + … Read more

Custom post type with slug for plural (archive) and for single

I’ve been searching a way to have kind of “two” slugs for a custom post, let me give an example: or for the archive for the single custom post 1 Answer 1 Both of these are controlled by the arguments passed to register_post_type, specifically, the rewrite and has_archive arguments: $args = [ … Read more

WordPress not respecting template hierarchy (fetches index.php instead of single.php or page.php)

I’ve encountered a strange error while developing a custom theme. After finishing editing the template for a custom post type single view, I passed onto working at the template files for pages and I ealized that WordPress was actually pointing to index.php template file rather than page.php in my theme for generating the page appearance. … Read more

query_vars in plugin not working?

I have a problem writing a plugin for wordpress. First, I register a new query_var and add a new rewrite rule: function nng_users_query_vars( $vars ) { array_push( $vars, ‘nng_users’ ); return $vars; } add_filter(‘query_vars’, ‘nng_users_query_vars’); function nng_users_rewrite_rules( $rules ) { $newrules = array( ‘benutzer/([^/]+)/?$’ => ‘index.php?pagename=nng_users&nng_users=$matches[1]’ ); $finalrules = $newrules + $rules; return $finalrules; } … Read more

When is it a good idea to build a permalink structure from scratch?

Is it a good idea to design a permalink structure from scratch? The requirements to the structure are as follows: Pages to be referenced by their structure ( Posts to be referenced by category and date ( Archives only available by category (, by category and year ( by category, year and month ( and … Read more

add_rewrite_rule() to route to file other than index.php

add_rewrite_rule( ‘^invite/([^/]+)’, ‘index.php?pagename=invite&iid=$matches[1]’, ‘top’ ); The “internal” rewrite rule above will route traffic through index.php using the pagename argument (which necessitates having a page with slug invite). I want to direct routing to invite.php (which will render an ICS calendar file and force download). I looked into the below implementation, however, this appears to directly … Read more

need a help for modify .htaccess rule [closed]

Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for WordPress Development Stack Exchange. Closed 9 years ago. Improve this question here is my wp .htaccess # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /wordpress/ RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f … Read more

How to rewrite custom post type with custom taxonomy urls?

I am working in a WP multisite which runs on a classipress theme and there is a custom post type “ad_listing” and custom taxonomy type “ad_cat“. Now the url is like this I need to rewrite this URL so it looks like and categories are nested so it can be nth level. Please … Read more

Rewriting URLs in WordPress

I am trying to solve a rewrite problem but don’t fully understand how to read the below code. I believe the event/industry/(.+)/?$’ is stating the format I want in my new url after rewritten, which should be And this part appears to be the parameter. => ‘index.php?post_type=eg_event&industry=’ . $wp_rewrite->preg_index(1) Is this a correct understanding? … Read more

Page Attachment Permalink Structure based on Menu Order?

I’ve been on a quest for the past couple of days reading up on Rewrite in WordPress but still can’t seem to figure out how to accomplish this. When using pretty links in WordPress, media attached to a page forms a URL like:…/attachment_name/ What I would like to do is create a … Read more