New answers tagged

0

This worked in the end, not sure why I was not getting anything showing up in the re-write rules initially but this worked. add_rewrite_rule( 'test-sale-yacht/([^/]*)?', 'index.php?pagename=test-sale-yacht&yacht_name_id=$matches[1]', 'top'); with yacht_name_id added in as a filter Jules


1

You're missing the WP $matches[1] syntax for the regex that gets matched. I think you want /? on the end too. Easiest way I found to test was to temporarily put flush_rewrite_rules() in whilst testing, then you don't have to do anything else. I have a similar regex which sends /foo/catname/ to index.php?taxonomy=category&term=catname, here's what I used ...


2

I just did a test and it seems like the rewrite rules imply ^ if you do not specify it. In my test I found: rule 'foo' matched url 'foo' rule '^foo' matched url 'foo' rule 'foo' did not match url 'afoo' rule '^foo' did not much url 'afoo' rule '.*foo' matched url 'afoo' So i had to explicitly add some matching regex at the start for it to match extra ...


0

This code produces the right structure but the post can't be found (404) That is because the custom rewrite tags (%filter_1% and %filter_2%) appeared as-is in the generated rewrite rules (in the database). So you need to register the tags so that they're replaced with the proper RegEx (regular expression) pattern when WordPress (re-)generates the rules. And ...


1

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: ...


2

It's quite easy, actually: Change the generated permalink structure so that it ends with the post ID and not the post slug (but it still contains the post slug): // After you registered the post type: register_post_type( 'ex_article', $args ); // .. run this code: global $wp_rewrite; $wp_rewrite->extra_permastructs['ex_article']['struct'] = 'sa/%...


0

Our custom rewrite rule works for top-level services but not child services. Your rewrite rule, or the query (the second parameter for add_rewrite_rule()) is just missing a service query: add_rewrite_rule( // wrapped for brevity '^consultancy/(.*)/?', // Here, add the &service=$matches[1] 'index.php?post_type=service&name=$matches[1]&...


0

@kingsgambit I want to pass the following URL Parameters at the end of every image URL in WordPress site: ?f=auto I am using WooCommerce and wanted to add following URL Parameters at the end of every image in my WordPress site. Can you please help me with that? Regards!!


Top 50 recent answers are included