0

There have been unanswered questions about this here and in the WordPress support forum.

Is it possible to have a conditional Permalink structure for all posts in a category?

for example, %year%/%category%/postname% for a given category, but for the other permalinks have a different structure (without the year for example)?

I'm not very efficient with htaccess, I can use some help please.

Thanks!

0

Answering My own question..

That was easier than I though.. I used the post_link filter to modify the permalink in the following way..

function custom_permalink( $permalink, $post ) {
    // Get the categories for the post
    $post       = get_post( $post_id );
    $category   = get_the_category( $post_id ); 
    $post_year  = mysql2date("Y", $post->post_date);
    $target_cat = 6; // Category we'd like to change permalink for

    if ( empty( $post_year ) ) return $permalink;

    if ( $category[0]->cat_ID == $target_cat ) {
        $permalink = trailingslashit( home_url( $category[0]->slug . '/' .$post_year .'/' . $post->post_name . '/'  ) );
    }

    return $permalink;
}

add_filter( 'post_link', 'custom_permalink', 10, 2 );

And of course, flushing permalinks by visiting the settings > permalinks page.

| improve this answer | |

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.