Edit Link Override Question

This topic contains 2 reply and 2 voices, and was last updated by sociallyfamous 11 years, 1 month ago
Viewing 2 Posts - 1 through 2 (of 2 total)
Author Posts
October 14, 2013 at 12:40 am 8976
sociallyfamous Hello all. I am using a custom permalink structure such as this /%region%/%postname%/ For this to work I had to add a bit of code into the fuctions.php which I have added to the bottom of the post. When I put the setting to YES in the edit link override option, I get a 404 error. The normal edit link with the NO setting works fine. If I change the permalink structure to /%postname%/ it works fine. What do I need to change to still make it work with my permalink structure? Hope you guys can help. -------------------------------------------------------
// Custom permalink for ctp *region*

add_filter('post_link', 'region_permalink', 10, 3);

add_filter('post_type_link', 'region_permalink', 10, 3);

 

function region_permalink($permalink, $post_id, $leavename) {

    if (strpos($permalink, '%region%') === FALSE) return $permalink;

     

        // Get post

        $post = get_post($post_id);

        if (!$post) return $permalink;

 

        // Get taxonomy terms

        $terms = wp_get_object_terms($post->ID, 'region');   

        if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;

        else $taxonomy_slug = 'keine-region';

 

    return str_replace('%region%', $taxonomy_slug, $permalink);

}   
October 14, 2013 at 4:42 pm 8991
Tareq Hasan Tareq Hasan

Try to change the priority from 10 to 9 and see if it works.

October 14, 2013 at 6:07 pm 8994
sociallyfamous sociallyfamous

Hello Tareq,

I have tried the following with no luck

add_filter('post_link', 'region_permalink', 9, 3);

add_filter('post_type_link', 'region_permalink', 9, 3);

Is that what you meant? And would you happen to have any other ideas?

Viewing 2 Posts - 1 through 2 (of 2 total)