views:

523

answers:

4

Hi there!

I want to change the post permalink schema on my WordPress 3.0-beta1 to use my new custom taxonomy.

Today I can use /%category%/%postname%/ and the /my-category/my-post/ URL, that's nice but I need to use another taxonomy instead "category" one.

I tried to use /%acervo%/%postname%/ but my URLs came with %acervo% on the URL instead the name of the "Acevo" (my taxonomy name) wich the post belongs to.

I found something related to WP_Rewrite but without sucess...

A: 

You could try using the WordPress plugin, No Category Base, and then hard code the taxonomy in with the postname wildcard, like so:

/acervo/%postname%/

Note that acervo does not have the percentage signs since it's "hard coded" and not a wildcard.

hsatterwhite
I don't want to hardcode anything... The post belongs to one or more `acervo` (my taxonomy) and I want to insert this value in the post permalink using wordpress funcions, hooks or filters (if necessary) to be able to rely on the `the_permalink()` function.
TiuTalk
I hear ya. I haven't messed around with WP3.0 enough to know if this can be done and I'm pretty sure their documentation is lacking at this point. Best bet would be to look in the source code where the permalinks setting is handled to see if anything has been changed/added.
hsatterwhite
A: 

Simply change your category base in Dashboard/Settings/Permalinks No need to get rid of the category base and then add it in again.

songdogtech
As I said in my question, I don't want to use category taxonomy... I need to use the `acervo` taxonomy in the URL... The category page and category-base has nothing to do with this.
TiuTalk
A: 

I get it... Changed the permalink structure to /%acervos%/%postname%/ and then dived into WP_Rewrite and added a new "replacement tag" replacing %acervos% with (.*) regexp.

TiuTalk
A: 

This should to the trick.

function acervo_permalink($permalink, $post_id, $leavename){
    if (get_option('permalink_structure') != ''){
        $post = get_post($post_id);
        $rewritecode = array(
            '%acervo%'
        );
        if (strpos($permalink, '%acervo%') !== FALSE){   
            $terms = wp_get_object_terms($post->ID, 'acervo');  
            if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $acervo = $terms[0]->slug;
            else $acervo = '';
        }
        $rewritereplace = array(
            $acervo
        );
        $permalink = str_replace($rewritecode, $rewritereplace, $permalink);
    } 
    return $permalink;
}
maukoquiroga