WordPress Rewrite

assuming u is a custom query var, you have to first add it to the array of recognized query vars: function wpa_query_vars( $query_vars ){ $query_vars[] = ‘u’; return $query_vars; } add_filter(‘query_vars’, ‘wpa_query_vars’); Then add an internal rewrite rule that accepts anything appended to vendors and passes that as the u query var: function wpa_rewrite(){ add_rewrite_rule( … Read more

Permalinks for WooCommerce Categories and Subcategories

I was able to resolve this with the following code which generates rewrite_rules for each subcategory, which is preferred during matching since it’s more specific: function wpse_291143_generate_taxonomy_rewrite_rules( $wp_rewrite ) { global $wp_rewrite; $base = “shop”; $rules = array(); $terms = get_terms( array( ‘taxonomy’ => ‘product_cat’, ‘hide_empty’ => false )); foreach($terms as $term) { $term_children = … Read more

add_rewrite_rule with 3 or fewer matches?

Well, apparently lots of trial and error pays off! I used this code instead, where I reversed my add_rewrite_rules and now it works perfectly. // Remember to flush the rules once manually after you added this code! add_rewrite_rule( // The regex to match the incoming URL ‘our-work/our-year/([^/]*)/([^/]*)/([^/]*)/?’, // The resulting internal URL: `index.php` because we … Read more

Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url

WordPress parses incoming URLs with a list of regular expressions, the rewrite rules. The first regex that matches the URL “wins”, and determines what kind of query will be executed. You can see the rewrite rules and play with different URLs with my Rewrite analyzer plugin. Whether or not pages take priority over other rules … Read more

flush_rewrite_rules not working on plugin deactivation, invalid URLs not showing 404

Have you tried delete_option(‘rewrite_rules’); on deactivate? I came across the following when investigating this problem and it did the trick for me: Typically you register post types on init. Some time after that, you get the deactivation action. A responsible plugin would remove its rewrite rules by flushing. However, it can’t undo the registration, so … Read more

Change the Permalink for wordpress attachment

Your rule works with the attachment ID, so I’m not sure how you’re using the title, but the answer is almost identical in either case. The filter you want is attachment_link: function wpd_attachment_link( $link, $post_id ){ $post = get_post( $post_id ); return home_url( ‘/images/’ . $post->post_title ); } add_filter( ‘attachment_link’, ‘wpd_attachment_link’, 20, 2 ); Change … Read more

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