admin管理员组

文章数量:1122846

When filtering the permalink structure it looks like this:

https://constructions-equipments/shop/swoof/brand-caterpillar/

But it should show like:

https://constructions-equipments/shop/?swoof=1&pa_application=caterpillar

When filtering the permalink structure it looks like this:

https://constructions-equipments/shop/swoof/brand-caterpillar/

But it should show like:

https://constructions-equipments/shop/?swoof=1&pa_application=caterpillar
Share Improve this question edited Apr 2, 2024 at 0:48 Tony Djukic 2,2594 gold badges18 silver badges33 bronze badges asked Apr 1, 2024 at 13:39 LM10LM10 12 bronze badges 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Apr 2, 2024 at 0:48
Add a comment  | 

1 Answer 1

Reset to default 0

You want to change the URL structure from something like /shop/swoof/brand-caterpillar/ to /shop/?swoof=1&pa_application=caterpillar so you can use wp built in rewrite rules and query parameters. You will need to add custom rewrite rules and handle query parameters accordingly.

add custom rewrite rules to map the desired URL structure to the appropriate query parameters.

Add code in your currently active theme of the functions.php file

1.Add Custom Rewrite Rules

function custom_rewrite_rules() {
    add_rewrite_rule('^shop/swoof/brand-([^/]+)/?', 'index.php?post_type=product&swoof=1&pa_application=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_rules');

This rule will rewrite URLs like /shop/swoof/brand-caterpillar/ to /index.php?post_type=product&swoof=1&pa_application=caterpillar

2.After adding custom rewrite rules, you need to flush the rewrite rules so that Wordpress can recognize them.

Go wp admin area to change the permalink structure Settings > Permalinks and simply click the "Save Changes" button.

URL structure is rewritten, you need to handle the query parameters in your theme or plugin to filter the products accordingly.

you can use WooCommerce hooks or custom query modifications to adjust the product query based on the swoof and pa_application parameters

本文标签: pluginsSwoof filter settings