How to Add Rewrite Ruled Argument Into Permalink Properly

I’m affraid this “nasty” solution would be the most effective than trying to write some cool function that will translate your permalinks into pretty permalinks: $permalink = rtrim( get_permalink( $id ), “https://wordpress.stackexchange.com/” ) . ‘/foo’ . ‘/2’; The rtrim part (removing trailing slash) is just for to be sure there are not going to be … Read more

Append custom parameter to taxonomy/term URI

You can try this: function my_car_rewrite_rules( $rules ) { $newrules = array(); // add a rule for this kind of url: // http://myhost.com/cars/ferrari/used/123 // => http://myhost.com/index.php?post_type=cars&ferrari=used&p=123 $newrules[‘^cars/([^/]+)/([^/]+)/([^/]+)$’] = ‘index.php?post_type=cars&$matches[1]=$matches[2]&p=$matches[3]’; return $newrules + $rules; } add_filter(‘rewrite_rules_array’,’my_car_rewrite_rules’); and remember to “save the permalinks” when testing. I added /cars/ so this rewrite will not overwrite your other pages. … Read more

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

Rewrite rule help for gallery plugin

I finally got my rewrite rules to work here: $home = get_post(Sunshine::$options[‘page’]); // Gallery add_rewrite_rule($home->post_name.”/gallery/([^/]+)/page/?([0-9]{1,})/?$”,’index.php?pagename=”.$home->post_name.”&sunshine_gallery=$matches[1]&paged=$matches[2]’,’top’); add_rewrite_rule($home->post_name.”/gallery/([^/]+)/?$”,’index.php?p=’.$home->post_name.’&sunshine_gallery=$matches[1]’,’top’); add_rewrite_rule($home->post_name.”/gallery/([^/]+)/?$”,’index.php?pagename=”.$home->post_name.”&sunshine_gallery=$matches[1]’,’top’); // Image add_rewrite_rule($home->post_name.”/image/([^/]+)/?$”,’index.php?pagename=”.$home->post_name.”&sunshine_image=$matches[1]’,’top’);

URL rewrite breaking pagination

This works: mysite.com/sermon/term/childterm/page2/ This does not: mysite.com/sermon/term/childterm/page2/ according to your rewrite rule, I guess what you mean is This works: mysite.com/sermon/term/page2/ This does not: mysite.com/sermon/term/childterm/page2/ I’m not a regex expert so I only come up with adding another rewrite rule to handle the childterm situaion add_rewrite_rule( ‘sermon/(.*?)/(.*?)/page/?([0-9]{1,})/?$’, ‘index.php?post_type=”.$cpt.”&’.$tax.’=$matches[2]&paged=$matches[3]’, ‘top’ );

Custom rewrites for pages and categories

If you want to have domain.tld/PAGE-NAME.php then you could just use %postname%.php as custom structure. // Edit As this approach seems to work for posts only, you might have a try with the structure /%postname%/. In addition, you put the following lines to your .htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*).php /$1/ [R=301,L] </IfModule> // … Read more

Canonicalization + Custom Post Types not working as expected

Think ive solved it and can’t believe what it was! On my rewrite rule I had: add_rewrite_rule( ‘custom-post-type/([0-9]+)/([^/]*)/?$’, ‘index.php?post_type=customposttype&p=$matches[1]’, ‘top’ ); Adding in and passing the post_name for the custom post type got it to start redirecting. add_rewrite_rule( ‘custom-post-type/([0-9]+)/([^/]*)/?$’, ‘index.php?post_type=customposttype&p=$matches[1]&customposttype=$matches[2]’, ‘top’ ); Anycase for now its late and it seems to have started working 🙂 … 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.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)