Add Rewrite Endpoint to CPT Archive

You’re getting the 404 most likely because your custom taxonomy is not assigned to the endpoint mask (EP_PAGES) used with your endpoint. Because add_rewrite_endpoint() does work with custom post types and taxonomies, but you need to assign the endpoint mask to the post type or taxonomy during registration, via the ep_mask key in the rewrite … Read more

Do I need to flush rewrite rules when creating new user if using custom author rewrite rules?

Yes, you should flush rewrite rules in this case, because you add rules for every author based on his nicename. To be more precise, you should flush them after any author changes his nicename also. And you do this using author_rewrite_rules hook, which is fired in wp_rewrite_rules() only when there are no rules in database. … Read more

How to use rewrite rule or rewrite endpoint to switch languages?

You cannot do this by just adding a rewrite rule, you need to change every recorded rules. Here is a simple way to do this: function my_rewrite_rules($rules) { $new_rules = array(); $new_rules[‘(?:de|en)/?$’] = ‘index.php’; foreach ($rules as $key => $val) { $key = ‘(?:de|en)/?’ . $key; $new_rules[$key] = $val; } return $new_rules; } add_filter(‘rewrite_rules_array’, ‘my_rewrite_rules’, … Read more

Uppercase to Lowercase in URL

This is NOT mod_rewrite rule, it’s WordPress rewrite rule and it proposes to parse variables from URL to wp_query (most of the time). You can apply your logic during parse_query filter hook., something like this. add_filter( ‘parse_query’, function( WP_Query $wp_query ) : WP_Query { foreach ( [ ‘symbol’, ‘exchange’ ] as $key ) { if … Read more

Associate the “add_rewrite_endpoint” and “$_GET”

Query parameters added using add_rewrite_endpoint() are available using get_query_var(). So if you register /en/ as an endpoint: function wpse_318560_en_endpoint(){ add_rewrite_endpoint(‘en’, EP_ALL); } add_action(‘init’, ‘wpse_318560_en_endpoint’ ); And don’t flush rewrite rules on init. Rewrite rules only need to be flushed once. See this note in the developer docs for a way to properly flush rewrite rules … Read more

add_rewrite_endpoint not working

Your code should (and does from quick check) work in principle. You should not be flushing permalink every page load, just once. Use rewrite helper like Monkeyman Rewrite Analyzer to see if rules are being generated, what they are, and how are they matching to real URLs in your site.

add_rewrite_rule isnt working, not getting added to rules array, why?

Try this. You also don’t want to include $wp_rewrite->flush_rules() inside your function as that would flush on every page load. add_action(‘rewrite_rules_array’, ‘new_rewrite_rules’); function new_rewrite_rules($rules){ $newrules = array(); $newrules[ ‘^lists/([^/]*)/([^/]*)/?’ = ‘index.php?lists=$matches[1]&post=$matches[2]’; return $newrules + $rules; } If you want to flush the rules only once then try this: add_action(‘init’, ‘flush_new_rule’); function flush_new_rule(){ global $wp_rewrite; if(is_array(get_option(‘rewrite_rules’)) … Read more

add_rewrite_rule confusion

Expanding on my comment: The Rewriting API is for rewriting URLs, not redirecting. So the URL won’t change. You’re just telling WordPress that /testpage/ should load page_id 81, but the URL will stay /testpage/. Regardless, I tried the below, (where 501 is an ID that exists on my install) and it worked fine, loading that … Read more

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