WooCommerce – Conditional for page created by rewrite_rule

In WordPress, the request path, e.g. path/to/something as in example.com/path/to/something?query=string&if=any, is saved in WP::$request which is accessible via the global $wp variable, so in your case, you can do so to check if the page is /dashboard/products: global $wp; // Note: No trailing slashes. $is_my_page = ( ‘dashboard/products’ === $wp->request ); // Or without the … Read more

Route subpage to Custom Post Type

I usually struggle with this, however this time I managed it relatively easy. Main reference for this answer is here: https://codex.wordpress.org/Rewrite_API/add_rewrite_rule I’d like to use anything in the below as discipline. /artists/djave_co/anything First of all, I added a “rewrite tag” function custom_rewrite_tag() { add_rewrite_tag(‘%discipline%’, ‘([^&]+)’); } add_action(‘init’, ‘custom_rewrite_tag’, 10, 0); Next, I did print_r($wp_query->query_vars) on … Read more

Rewrite Rule for Post Meta

Okay! So I got this working by just changing the rewrite_rule to include the event… function aca_award_cat_rewrite_rule() { add_rewrite_rule( ‘^awards/([^/]*)/award-category/([^/]*)/?’, ‘index.php?competition=$matches[1]&award_category=$matches[2]’, ‘top’ ); }

Set parent for custom post type archive rewrite url

First, you need to register the %office% rewrite tag: // First, add the rewrite tag. add_rewrite_tag( ‘%office%’, ‘([^/]+)’, ‘post_type=office_members&office_name=” ); // Then call add_permastruct(). add_permastruct( “office_members’, … ); Then, add the custom office_name arg to the public query vars so that WordPress reads/parses it from the URL: add_filter( ‘query_vars’, function ( $vars ) { $vars[] … Read more

How to override url params with rewrite rules vars?

“hi” message is displayed instead of “hello” in the second example Yes, because that’s how it works: query_vars is a hook for registering custom query vars that are public, so if the URL query string contains the custom query var, then WordPress will set the query var to the value parsed from the query string. … Read more

Bilingual WP site: How to achieve different URL sturcture rule based on its language?

Try the following steps: Add the rewrite rules for the <language>/blog/%category%/%post_id% structure. I used the post_rewrite_rules hook to add the rewrite rules, but for generating the rewrite rules, I used WP_Rewrite::generate_rewrite_rules() the same way WordPress core used it to generate the rewrite rules for the default permalink structure (that you set via the Permalink Settings … Read more