Rewrite URL variable to custom path

You could add the path via add_rewrite_endpoint, then alter the query via the pre_get_posts action. Here’s a proof-of-concept example that alters the posts_per_page when domain.com/highest-rated/ is requested: // add the endpoint function wpa85664_add_endpoint(){ add_rewrite_endpoint( ‘highest-rated’, EP_ALL ); } add_action( ‘init’, ‘wpa85664_add_endpoint’ ); // check if the endpoint is in the current request // and alter … Read more

URL Redirect in WordPress

For this kind of rewriting, I’m using this code (haven’t tested this one exactly, so may contain minor bugs): add_filter( ‘query_vars’, ‘binda_query_vars’ ); function binda_query_vars( $vars ) { $vars[] = ‘pp’; return $vars; } add_action( ‘generate_rewrite_rules’, ‘binda_rewrite_rules’ ); function binda_rewrite_rules( $wp_rewrite ) { $wp_rewrite->rules = array( ‘news/([0-9]{1,})/([0-9]{1,})/?$’ => $wp_rewrite->index . ‘?post_type=news’ . ‘&pp=’ . $wp_rewrite->preg_index( … Read more

Need Help With A Rewrite Issue

You could do something like this to rewrite rules for author titles, check out the monkeyman rewrite analyzer to figure out, following code should be in your functions.php add_filter(‘rewrite_rules_array’, ‘my_insert_rewrite_rules’); function my_insert_rewrite_rules($rules) { // Implement this function to add all the new rules to $rules array passed in $newrules = array(); $authors=get_users();//http://codex.wordpress.org/Function_Reference/get_users foreach($authors as $author) … Read more

Custom Rewrite Problem

You can try these rules: reviews/([^/]+)/page/?([0-9]{1,})/?$ reviews/([^/]+)/?$ It’s informative to check out the active rewrite rules with: function show_rewrite_rules( $rules ) { if(is_admin()) echo “<pre>”.print_r($rules,true).”</pre>”; return $rules; } add_filter(‘rewrite_rules_array’,’show_rewrite_rules’); and then visit /wp-admin/options-permalink.php. There exists also some good plugins for analysing the rewrite rules, for example the Monkeyman Rewrite Analyzer.

username in rewritten URL, howto use it in a template

I created a new function, with which i get the username. Is there any problem with using it? Or is there a cleaner way of doing it? function getmyuser() { $test = substr($_SERVER[“REQUEST_URI”], strrpos($_SERVER[“REQUEST_URI”],”/user/”)+6); return str_replace(“https://wordpress.stackexchange.com/”,”, $test); }

how rewrite is working in wordpress

You can best analyse the URL rewrites with the URL Rewrite Analyser which has been developed by Jan Fabry, see the following answer for more information. Furthermore you can change the structure of the permalinks under the Options –> Permalinks of the WordPress admin section.

Rewriting WordPress URLs

The first important difference between your rewrite rule, and the ones that Pippin has provided is that all of his rewrite rules point to index.php. This is an absolute must, you won’t get it to work any other way, all requests must point to index.php with your query vars appended. The second important thing to … Read more