`query_var` values empty in theme file after `add_rewrite_rule` redirection

Changing the add_rewrite_rule did the trick: add_rewrite_rule(‘^periodicals/([^/]+)-‘.$tlv[‘code’].'[/]?$’, ‘index.php?periodicals=$matches[1]&post_type=periodicals&name=$matches[1]&mlang=’.$tlv[‘code’], ‘top’); So, I assume for custom post types, using add_rewrite_rule with index.php as query need some extra query variables. A sample will be as: add_rewrite_rule(‘^<custom_post_type>/([^/]+)-‘.$tlv[‘code’].'[/]?$’, ‘index.php?<custom_post_type>=$matches[1]&post_type=<custom_post_type>&name=$matches[1]&mlang=’.$tlv[‘code’], ‘top’);

Trying to Find the PHP File/Function that Handles a Specific Form Action URL

The URL you are looking at does not exist in the filesystem, it’s a WP rewrite rule. Ugly URLs look like this: index.php?queryvar=value Pretty URLs look like this: /my/pretty/permalinks But if your server does not or cannot support the needed HTAccess or rules to set up pretty permalinks, there is a workaround: /index.php/my/pretty/permalinks, where index.php … Read more

Custom taxonomy still using query URL after fixing error

To address the issue of your custom taxonomy resource-category not displaying correctly even after fixing the custom post type and flushing permalinks, you can follow these steps: Double-check the Registration Code. Flush Permalinks Again: Go to Settings > Permalinks and click on Save Changes. This will flush the rewrite rules and update the permalinks. Clear … Read more

How to customize the url structure?

The problem is your slug parameter, it can’t just be / – you need to have something that identifies the URL as being this taxonomy. It defaults to the taxonomy key which in this case would be course_cat but in the interest of human-readable URLS you could do this instead: ‘rewrite’ => array( ‘slug’ => … Read more

How to make such a structure for cpt?

If you use the Advanced Custom Fields plugin (ACF) to create your custom taxonomy for your custom post type then you can just check the box to make it hierarchical. It will then automatically create a url structure matching the hierarchy.

CPT with URL rewrite showing as 404

Step 1: Flush Rewrite Rules Manually: Visit Settings > Permalinks and click “Save Changes”. Programmatically (temporarily): function my_custom_flush_rewrite_rules() { flush_rewrite_rules(); } add_action( ‘init’, ‘my_custom_flush_rewrite_rules’ ); Step 2: Add Custom Rewrite Rules function custom_rewrite_rules() { add_rewrite_rule( ‘^products/([^/]+)/([^/]+)/?$’, ‘index.php?post_type=product&product_category=$matches[1]&name=$matches[2]’, ‘top’ ); } add_action( ‘init’, ‘custom_rewrite_rules’ ); Step 3: Modify post_type_link Filter function add_custom_rewrite_rule( $post_link, $post, $leavename ) … Read more