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

Remove date rewrite rule for custom post type archive page

You have just a little mistake in your preg_match, instead of this: if ( preg_match(‘/(year=\$matches|monthnum=\$matches)/’, $rewrite) ) { do this: if ( preg_match(‘/(year=\$matches|monthnum=\$matches\/)/’, $rewrite) ) { I was looking for a solution to clean a lot of rules, this source is useful: https://wpreset.com/remove-default-wordpress-rewrite-rules-permalinks/ My final code is this, it can be customized allowing more or … Read more

Redirect all URLs in WordPress and Permalink to by country to subdomain

You can try to check the visitor country via the geojs.io, and then build the logic for redirecting. See the JS code below: geoTargeting(); function geoTargeting() { return new Promise((resolve, reject) => { fetch(‘https://get.geojs.io/v1/ip/country.json’).then(response => response.json()).then(data => { const currentHostname = window.location.hostname; const currentPath = window.location.pathname; let newUrl; if (data.country === ‘US’) { // Check … Read more

rewrite for subpage seems to loose parameter

That’s because in the URL https://mydomain.cl/vehiculos/vehiculo/1599 there are no query parameters, and no GET parameters. This is because you rewrote them into the URL, and they are now query variables. For the same reason $_GET[‘pagename’] wouldn’t work, neither will $_GET[‘auto-id’]. Instead, use get_query_var( ‘….’ );.

How to make 2 (or more) custom post type post pages sit under the same slug?

You were getting /video-demos-tours/post-name instead of /resources/post-name because the following line in your theme_build_post_args function is setting the rewrite slug to the post type slug (video-demos-tours): $args[‘rewrite’][‘slug’] = $slug; So you should fix that, but as for how, that is up to you. But then, although fixing that would give you the permalink structure you … Read more

WordPress fallback rewrite

Since you want to check if a custom post exists and if not, then load a page, you can’t simply rely on two rewrite rules because the second rule will not act as a fallback. Instead, you can handle this programmatically. Give this a try: First, add a custom query var to hold your potential … Read more

How to keep rewrite_rule without flushing each time?

My usual trick to a) flush as required but b) not flush on every page load is to use an option to determine if the rewrites have changed, and flush only if they have indeed changed. Something like this: add_action( ‘wp’, ‘wpse_421338_maybe_flush_rewrites’ ); function wpse_421388_maybe_flush_rewrites() { $rewrite_obj = new WP_Rewrite(); $rewrites = $rewrite_obj->wp_rewrite_rules(); // Compare … Read more

Is it possible to use the same slug structure for a taxonomy and for some pages?

Figured out a solution! This intercepts the query at parse_request, checks if a page with a matching slug exists, and if so, changes the request to a page request. /** * Fix rewrite conflicts between “project_category” and “page” * * @param WP $query * @return WP */ function prefix_parse_request_fix_rewrite_conflicts_project_category(WP $query): WP { if (isset($query->query_vars[“project_category”])) { … Read more