Open category archive page by url parameter
-
Hi,
I can’t find this answer. In wordpress if you open url with parameter mysite.com/?cat=1 automaticaly wordpress open the archive page of category 1 of posts like mysite.com/category/name-of-category/.
In Woocommerce I can’t find how I can open the archive page with parameter in url like ?cat=22
I need this because I want to use buttons to link to category product archive page and if one day I change the name of the category the link not broken.For example I have 2 categories for products: CategoryA and CategoryB
In home page I have 2 buttons: “Show CategoryA” and “Show CategoryB”.
I set href to buttons like: mysite.com/product-category/categorya/
but if I change the slug of CategoryA my button will not work.I’m a developer and I created my solution but I want to ask you if exist the possibility to pass parameter cat id to url to open archive page of product category.
This is my solution passing parameter ?product_cat=22
example: mysite.com/?product_cat=22add_action( 'wp_loaded', 'my_muplugins_loaded', 10, 0 ); function my_muplugins_loaded() { if( isset($_GET['product_cat']) ) { $term = get_term_by('term_taxonomy_id', (int)$_GET['product_cat']); if( $term ) { $link = get_term_link($term); wp_redirect($link, 301); exit; } } }
- The topic ‘Open category archive page by url parameter’ is closed to new replies.