I have done this which seems to work but not sure if the right way to
go about it?
Yes, you can create a custom Page template which displays posts in your custom post type, and use that template with those “industry” pages.
And if you want, you can create a single Page which will handle all the “industry” requests/URLs like /industry/woodworking
. And then you can use add_rewrite_rule()
to add a custom rewrite rule which redirects the requests to that Page.
Or you can also redirect them to the tag archives. Example:
add_action( 'init', function(){
add_rewrite_rule( '^industry/woodworking',
'index.php?tag=woodworking&post_type=Products',
'top' );
} );
Just noticed that this only works with single words. As soon as a tag
word has a space in it then it doesn’t pick it up.
As pointed in my comment, that’s because the tag
parameter expects one or more tag slugs and not names. Examples:
-
'tag' => 'tag-one, tag-two'
— correct. -
'tag' => 'Tag One, Tag Two'
— incorrect.
You can check the full parameters list here.