WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Redirect user if there's only 1 post in category/tag page ? (4 posts)

  1. jacky_K
    Member
    Posted 1 year ago #

    Hi,

    Is there a plugin (or hack) that allows me to redirect users if there's only 1 post in category/tag page ? I mean redirect them directly to this single post.

    I tried http://wordpress.org/support/topic/a-plugin-to-redirect-user-if-theres-only-1-post-in-categorytag-page?replies=2

    function redirect_to_post(){
        global $wp_query;
        if( is_archive() && $wp_query->post_count == 1 ){
            the_post();
            $post_url = get_permalink();
            wp_redirect( $post_url );
        }
    } add_action('template_redirect', 'redirect_to_post');

    Works fine on one of my blog. But on my other blog writes “Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.” What’s the problem?

  2. riversatile
    Member
    Posted 1 year ago #

    I'm only know this solution me too.

  3. jacky_K
    Member
    Posted 1 year ago #

    On my test blog thats work fine. On another blog first worked. Then stopped.
    Disable plugin, changed themes... Does not help. Reinstall wordpress?

  4. jacky_K
    Member
    Posted 1 year ago #

    Now everything is OK. I reinstalled wordpress.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags