Custom rewrite rules for a $_GET request

First add get to query vars array: function add_query_vars_wpa12572($vars) { $vars[] = ‘get’ return $vars; } add_filter(‘query_vars’, ‘add_query_vars_wp12572’); then add the rewrite rule function author_rewrite_rules_wpa12572( $wp_rewrite ) { $newrules = array(); $new_rules[‘get_(\d*)$’] = ‘index.php?get=$matches[1]’; $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } add_filter(‘generate_rewrite_rules’,’author_rewrite_rules_wpa12572′);

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

Is there a log for the ajax calls made when changing a post’s slug?

If we trace the Ajax process after you click OK, we would walk the following path from the core and into the database: Press OK on Edit slug: \ \-> AJAX POST request with action=sample-permalink Action: wp_ajax_sample-permalink \ \-> function: wp_ajax_sample_permalink() \ \-> function: get_sample_permalink_html() Filter: get_sample_permalink_html \ \-> function: get_sample_permalink() Filters: get_sample_permalink, editable_slug \ … Read more

How can I Rewrite a ‘page’ URL based on query string parameters?

You can add a rewrite rule such as the following. Make sure to register your public query vars with WordPress so it recognizes your rewrite rule vars. add_rewrite_rule(‘^(tips)/([^/]*)/([^/]*)/?’, ‘index.php?name=$matches[1]&id=$matches[2]&filter_id=$matches[3]’,’top’); add_filter(‘query_vars’, ‘foo_my_query_vars’); function foo_my_query_vars($vars){ $vars[] = ‘id’; $vars[] = ‘filter_id’; return $vars; } Visit the Permalinks Settings page to flush your permalinks. You can access your … Read more

%tag% in permalink not working

@Atari asked for a solution.. People who do not have one should not butt in! I have the same issue. All other %category% %postname% %post_id% etc. resolve fine, but %tag% remains %tag% in the final permalink! I think it is a bug. I came across a patch which was for an older version. I did … Read more

Include Taxonomy slug in post url

Add Custom Taxonomy Tags to Your WordPress Permalinks What you wish to do is have your taxonomy available to use within the Permalink structure e.g. /%actor%/%postname% First you write your taxonomomy as you have already done, but you require additional fields: add_action(‘init’, ‘add_actor_taxonomy’); function add_actor_taxonomy() { if (!is_taxonomy(‘actor’)) { register_taxonomy( ‘actor’, ‘post’, array( ‘hierarchical’ => … Read more

Changing pemalink structure to /%post_id%/%postname%/

I think I got it. Made a test site. With permalink structure: year/moth/day/postname. Published a post. Then changed permalinks to postID/post-name. Tested with looking at network stats from the browser. Here’s what I got, a 301 redirect, after trying example.com/2018/11/04/hello-world/ from my browser: I tested another thing. Using different permalink structures, I tried to make … Read more

How to use first tag in permalinks

Use add_rewrite_tag() to register the placeholder, and filter post_link to insert the correct tag. Use get_the_tags() to get the tags for a post. Sample plugin I have used in a project: <?php /** * Plugin Name: T5 Tag as rewrite tag * Description: Use <code>%tag%</code> in permalinks. * Version: 2012.09.02 * Author: Thomas Scholz * … Read more

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