I have a custom post type:

register_post_type( 'tour',
        'labels' => [
            'name'          => __( 'Tour shows' ),
            'singular_name' => __( 'Tour show' )
        'public'              => true,
        'menu_icon'           => 'dashicons-tickets-alt',
        'has_archive'         => 'tour', // also tried true
        'with_front'          => true,
        'exclude_from_search' => true, 
        'taxonomies'          => ['post_tag'],
        'rewrite'             => ['slug' => 'shows-on-tour'],
        'supports'            => ['title', 'editor', 'thumbnail']

(this has been butchered a bit while trying to make it work)

I'm having an issue where by when I do get_permalink($tour->ID) it returns:


This then redirects you to


The problem is I have a separate post type for "shows not on tour", so whenever I link to:


I end up at:


How can I use get_permalink on either post type and have it return the full url to the post with the correct post type on the front?


In the editor, when I edit the tour it clearly says:


and the not on tour:


So the issue must lie with how / where I'm calling get_permalink.


In my case I was trying to get the permalink before I had set up the post types.

I double checked the Action Reference: https://codex.wordpress.org/Plugin_API/Action_Reference

And updated the hooks I was using to trigger my theme setup. Once done, the get_permalink worked as expected.

| 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.