Site logo

Archived topic

Redirect category to a page

15 replies · Started by Nacho on November 6, 2020

Viewing posts 1–15 of 16

Hello,

How can I redirect 1 category archive page to a custom page or post that has the same slug?

Thanks a lot.

Hello David,

But that works for all categories, what about for just one category?

Thanks a lot.

Try changing this line:

if ( is_admin() ) {

to

if ( is_admin() && !is_category( 'category-slug' ) ) {

Change the category-slug to the slug of the Category you want to redirect.

Hello David,

I´ve tried that but it redirects to 404 page.

Here is the code:

add_filter('request', function( array $query_vars ) {
    if ( is_admin() && !is_category( 'noticias' ) ) { 
        return $query_vars;
    }

    if ( isset( $query_vars['category_name'] ) ) {
        $pagename = $query_vars['category_name'];

        $query_vars = array( 'pagename' => "$pagename" );
    }

    return $query_vars;
} );

How can I solve this?

Thanks a lot.

Bests.

Hello again David,

Is it a problem that the page we´re trying to refer is a post and not a page?

Maybe I should´ve explained better. So what I want is 1 category page redirect to a page and the others to the category archive page.

And also I actually want to send particular category page to a custom page and subcategories to the category archive page if this helps.

So for example, mydomain.com/news go to the news custom page and mydomain.com/news/economy go to the category archive page.

Thanks a lot.

Is the News archive where the latest posts would normally be displayed ?

Hello David,

Nope, News archive is not where the latest posts would normally be displayed. For that I´ve a blog category.

Let me explain, I´ve this categorization:

- Category News: Subcategory Economy, Subcategory Society.
- Category Freelancers: Subcategory Taxes, Subcategory Social security.

So for News and Freelancers which are categories I want to create a more complex page than the one Wordpress gives you for categories. That´s why I want to redirect those category archive pages to a custom page which is actually a post.

Hope it makes sense.

Thanks a lot David.

Hmmm... does the function i provided work correctly if you use a Page ?

Hello David,

Nope, it does not work.

How can I give you more information so you I can help you?

Thanks a lot.

I am not sure.
The only alternative would be to use a Redirection plugin or to have a template custom developed for this purpose.

Hello David,

I´m quite lost but thanks a lot.

Have a good day man.

Sorry I couldn't be of much help. This is a really tricky thing to deal with.

Hello David,

Yeah, super tricky.

Thanks for the help man.

This archived topic is closed to new replies.