• Resolved phil404

    (@phil404)


    Currently, I am using the “WordPress Category Archive” plugin with WP 2.9.2 in order to create an archive widget – much like the default Archive widget – that generates a list of years (linked) for posts within a specified category.

    WordPress Category Archive
    https://www.ads-software.com/extend/plugins/wp-category-archive/

    Permalink configuration:
    /%category%/%year%/%monthnum%/%postname%/

    This very same setup does not work in WP 3.0 when using anything but the default permalink option.

    Have the rewrite rules changed in WP 3.0?

    Thanks.

    -phil

Viewing 15 replies - 16 through 30 (of 35 total)
  • I looked at the WordPress 3.0 code. The behavior is caused by a change to how the redirect_canonical function handles categories, tags and taxonomies in wp-includes/canonical.php.

    I don’t know the code well enough to know if this is a good fix, but I moved a section of the 3.0 code that deals with taxonomy to inside the is_tax() if block, and things seem to work fine now.

    The original 3.0 code looks like:

    if ( is_category() ) {
         $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']);
    } elseif ( is_tag() ) {
        $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']);
    } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:
        $tax = get_taxonomy( $obj->taxonomy );
        if ( false !== $tax->query_var)
            $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);
        else
            $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);
    }
    $tax_url = parse_url($tax_url);
    if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
        parse_str($tax_url['query'], $query_vars);
        $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
    } else { // Taxonomy is accessable via a "pretty-URL"
        $redirect['path'] = $tax_url['path'];
    }

    I updated the bottom chunk of code that deals with tax_url to be inside the elseif (is_tax()) block.

    if ( is_category() ) {
         $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']);
    } elseif ( is_tag() ) {
        $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']);
    } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:
        $tax = get_taxonomy( $obj->taxonomy );
        if ( false !== $tax->query_var)
            $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);
        else
            $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);
        $tax_url = parse_url($tax_url);
         if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
            parse_str($tax_url['query'], $query_vars);
            $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
        } else { // Taxonomy is accessable via a "pretty-URL"
            $redirect['path'] = $tax_url['path'];
        }
    }

    So I think WordPress needs to be updated and not the plugin.

    Thread Starter phil404

    (@phil404)

    Thanks, Hugh! I’m going to give your fix a try.

    Thread Starter phil404

    (@phil404)

    Well, I implemented your code fix and all seems to be working well. Thanks again, Hugh. You saved us having to go with an ugly work-around.

    Whew. HUGE sigh of relief. I faced the exact same problem as Phil (I think our name is cursed right now) and implemented Hugh’s solution. It worked beautifully. Thanks a ton.

    Thread Starter phil404

    (@phil404)

    Resolved with WP 3.0.1.

    Um, it looks to me as if there is still a problem with the rewrite in WP 3.0.1. (see other threads on permalinks) Pretty links to pages don’t work. Should I use Hugh’s solution even if I’m using WP 3.0.1?

    Using 3.0.1 and it’s still not working. Without changing any code, the query ?m=2010&cat=4 redirects to the archive page for category 4 (but not any specific month or year).

    Using the change Hugh suggested, the query ?m=2010&cat=4 redirects to the archive page for the year 2010 (but shows all categories).

    This only applies when using the non-default permalink structure of course.

    Ideas?

    I’m having this issue too with a website I’m in the midst of developing. I’m using the most recent version of WP, with permalinks set, but the links output as m=2011&cat=3 and redirect to a refresh of the page. I’ve also noticed it’s only generating a single year in the list, but that might be another issue altogether.

    Has anyone ascertained a fix for this, or perhaps has located a similar widget with better functionality?

    Cheers!

    Figured out a quick fix. This works in WP 3.1.

    In wp-includes/canonical.php, find this line:

    } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) {

    Change it to this:

    } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && ! (count($_GET) == 2 && !empty($_GET['cat']) && !empty($_GET['m']))) {

    Explanation: The category archive plugin creates links to URLs like this: https://www.myblog.com?cat=5&m=200910 (this means, show me all posts in category 5 for Oct. 2009). When permalinks are on, the above conditional sends us into code that retries to rewrite the query in a “prettier” format.

    The changed conditional says that if the requested URL looks like a category archive URL, don’t try to rewrite the query. That means your category archive URLs will be “ugly” but at least they work. And permalinks for regular posts will still be correct.

    I tried on my blog (www.playitusa.com) but it doesn’t work.

    I have the same problem. I am using WordPress 3.1 and I tried changing the code as per above, but it doesn’t work. I need to have Permalinks on and Category archive to work once a specific month is clicked on. Any ideas anybody?

    Bump!

    Any resolution to this in WordPress 3.1?

    Same problem as petra5.

    At everyone who tried using my hack, what does your permalink structure look like?

    Hi fongandrew,

    I applied your edit to linke 98 of canonical.php

    /%category%/%year%/%monthnum%/%post_id%/

    .htaccess

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    But yeah it is still stuck.

    /%category%/%year%/%monthnum%/%post_id%/%postname%/

    But, whatever structure you could use, it doesn’t matter, simply doesn’t work.

    But, before last wp update, it worked!

    What happened in last update?

Viewing 15 replies - 16 through 30 (of 35 total)
  • The topic ‘Permalink rewriting in 3.0’ is closed to new replies.