Using get_query_var() from a plugin

Hook into parse_query instead: add_action( ‘parse_query’, function() { add_rewrite_rule( ‘go/([^/]+)/?$’, ‘index.php?redirect_to=$matches[1]’, ‘top’ ); add_rewrite_tag( “%redirect_to%”, ‘([^&]+)’ );` } ); Reason: init is too early, query_vars haven’t been set yet. wp_head is too late, no can redirect at that point.

Flush rewrite rules on option update with Settings API

I register custom post type on init action and the validate which I’m writing about is set to register_setting inside admin_init action. This is the key to your issue. You’re registering the custom post type, and presumably you’re setting up the rewrite rules in that registration. When you call flush_rewrite_rules(), the rules are rebuilt right … Read more

Adding a rewrite rule to page that has no fixed variables and pagination

Got it to work, changing the regex from (.+) to (.*) Maybe helpful for others searching same rewrite on search and pagination. add_rewrite_rule(‘discover/interiors/interior-results/(.*)/page/([0-9]{1,})/?’, ‘index.php?pagename=discover/interiors/interior-results&tag1=$matches[1]&paged=$matches[2]’, ‘top’ ); add_rewrite_rule(‘discover/interiors/interior-results/(.*)’, ‘index.php?pagename=discover/interiors/interior-results&tag1=$matches[1]’, ‘top’ );

Relative links stop working after moving wordpress site from hosting to localhost

If you are in https://localhost/cc and use a relative lnk with href=”https://wordpress.stackexchange.com/login” (relative to current domain/site), the browser (not WordPress) will take you to https://localhost/login; if the link is href=”https://wordpress.stackexchange.com/questions/267557/login” (relative to current path) the browser will take you to https://localhost/cc/login. Relative links work like that, nothing to do with WordPress. That is why many … Read more

Custom rewrite after the default term link URL

(Revised answer) So Let’s See The Issues With Your Rewrite Rule.. The first parameter passed to add_rewrite_rule() (which is the regular expression pattern) should not start with home_url() or any functions which outputs the website URL. So this is wrong: home_url() . ‘/car/([^/]*)/([^/]*)/?’ because the generated regular expression (RegEx) pattern would be: http://example.com/car/([^/]*)/([^/]*)/? which will … Read more

How to add custom taxonomy in custom post type permalink?

Solution would be a little tricky but you’re on the right path. You need to register taxonomy and post type with dynamic rewrite: function wpse346452_cpt() { register_taxonomy( ‘campaign’, ‘asset’, array( ‘label’ => ‘Campaing’ ) ); register_post_type( ‘asset’, array( ‘public’ => true, ‘label’ => ‘Asset’, ‘rewrite’ => array( ‘slug’ => ‘%campaign_name%’, ), ) ); } add_action( … Read more

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