1

I have a custom post type called listing and taxonomy for this listing is called listing_cat.

At the moment my wordpress permalinks appear in this format

localhost/wordpress/listing/listing_cat/post_name

I want to remove listing from permalink so it would appear in this format.

localhost/wordpress/listing_cat/post_name

Problem is when I remove listing from permalink with the help of "post_type_link" filter it direct me to 404 Page.

Here is the code that I am using that I have taken from another question.

add_filter('post_type_link', 'projectcategory_permalink_structure', 10, 4);
function projectcategory_permalink_structure($post_link, $post, $leavename, $sample) {
    if (false !== strpos($post_link, 'listing')) {
        $projectscategory_type_term = get_the_terms($post->ID, 'listings_categories');

        if (!empty($projectscategory_type_term)){

           // var_dump($projectscategory_type_term);
            $post_link = str_replace('listing', array_pop($projectscategory_type_term)->
                slug, $post_link);
        } else{

            $post_link = str_replace('listing', 'uncategorized', $post_link);
        }
    }

    return $post_link;
}

What is workaround of this problem.

Thanks

  • Did you click on the permalink setting in the WP Admin to refresh the permalinks settings? You have to refresh that for your code changes to stick. Go to settings > permalinks > save permalinks – Howard E Aug 20 '14 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.