0

I have set template taxonomy-event_type.php which displays just right on http://localhost:8000/types/<type_name>/.

What I need now is to:

  • either redirect when user lands on http://localhost:8000 to this page,
  • or use this template with (what wouldn't be greatest, as i'm checking the url and setting navigation items as active according to the url)

So something like (PSEUDOCODE):

if is_home(): 
   redirect('types/type1')

or

use_template('taxonomy-event_type','type1');

is it possible?

1
  • Note that the template doesn't determine the posts that get shown, so if you did load that template on the homepage, it would be the same posts you saw on the homepage before but in that template, not the posts from a particular term. URL creates query -> query fetches posts -> query + posts determines template to load
    – Tom J Nowell
    Mar 20, 2021 at 23:26

1 Answer 1

0

Found a solution:

// redirect on homepage to taxonomy
add_action("template_redirect", function() {
    if (is_front_page()) {
        return wp_redirect(get_term_link('type1', 'event_type'));
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.