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

Redirect OLD/Path to NEWURL/Path

<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^olddomin\.com RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L] </IfModule> This is what you’re looking for, before the WP block in your .htaccess.

How to work with URLs where sometimes a post or a subcategory is in the same part of the URL structure

Your challenge lies in the way WordPress interprets URL patterns and resolves them to query variables. When you have a URL structure where the third segment can be either a subcategory or a product name, WordPress struggles to differentiate between the two. This is a common issue in WordPress when using custom post types and … Read more

Is there a way to create a single rewrite rule to handle multiple variables depending on what is present?

I was able to make this work by using a power set function and then using that array to create individual rewrite rules. add_action(‘init’, ‘ebd_custom_rewrite_rules’); function ebd_custom_rewrite_rules() { $taxonomies = array( ‘engine-work’, ‘engine-specialty’, ‘application-specialty’, ‘machining-capability’, ‘dyno-facility’, ‘shop-region’); $combinations = ebd_get_array_power_set($taxonomies); $element_size_min = 2; foreach ($combinations as $combination) { if ($element_size_min <= count($combination)) { // skip … Read more