`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’);

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.

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( ‘….’ );.

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

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