admin管理员组

文章数量:1122846

At this point I have tried everything I know to fix the issue.

Issue: preview only works right after a custom posts is loaded or updated. If you make any changes or hit preview twice without updating the preview 404s. Pages and blog post do not 404 the previews.

We were using the ACF and CPUI plugins and roots theme. I have turned off all the plugins, switch to the 2014 theme, add the CPT manually, and Update WP core.

We have a lot of Custom post types in our site and rebuilding would be a huge pain.

Has anyone dealt with this issues? Anything helps.

Thanks!

At this point I have tried everything I know to fix the issue.

Issue: preview only works right after a custom posts is loaded or updated. If you make any changes or hit preview twice without updating the preview 404s. Pages and blog post do not 404 the previews.

We were using the ACF and CPUI plugins and roots theme. I have turned off all the plugins, switch to the 2014 theme, add the CPT manually, and Update WP core.

We have a lot of Custom post types in our site and rebuilding would be a huge pain.

Has anyone dealt with this issues? Anything helps.

Thanks!

Share Improve this question asked Oct 11, 2014 at 19:27 user1547761user1547761 11 silver badge3 bronze badges 4
  • Would you walk us through the situations where the preview works and where it doesn't work? What do you mean by "right after a custom posts is loaded or updated"? Are you having issues with Pages or Posts? – Seamus Leahy Commented Oct 11, 2014 at 20:45
  • Following up on that, would you link to the CPUI plugin? – Seamus Leahy Commented Oct 11, 2014 at 20:47
  • 1 Preview works: Pages and Posts. Preview Doesn't work: Custom Post Types - When you click preview it 404s whenever you add anything to be previewed, but haven't saved or clicked update. wordpress.org/plugins/custom-post-type-ui – user1547761 Commented Oct 11, 2014 at 22:26
  • Sorry, but I wasn't able to reproduce the issue. Try disabling pretty URLs to see if something with the rewrite rules is messing with it. – Seamus Leahy Commented Oct 12, 2014 at 21:59
Add a comment  | 

4 Answers 4

Reset to default 1

One of the parameter that you can pass to the supports argument is post_formats, removing this argument will fix the problem with the preview redirecting to a wrong or non-existing url. Code sample:

    if ( ! function_exists('custom_post_type') ) {

    // Register Custom Post Type
    function custom_post_type() {

        // some code

        $args = array(
            // 'supports'            => array( 'title', 'editor', 'author', 'thumbnail', 'revisions', 'post-formats', 'comments', 'sticky'),
            'supports'            => array( 'title', 'editor', 'author', 'thumbnail', 'revisions', 'comments', 'sticky'),
            'taxonomies'          => array( 'category', 'post_tag', 'your_cpt_pictures', 'your_cpt_updates', 'your_cpt_outline' ),
            'capability_type'     => 'post'
        );
        register_post_type( 'your_cpt', $args );

    }

    // Hook into the 'init' action
    add_action( 'init', 'custom_post_type', 0 );

I had the same issue. I was using CPT UI and ACF. To resolve the issue i went into CPT UI > Edit Post Types and disabled support for Post Formats

Having the exact same issue, if anyone used CPT UI to create them, turn on REVISIONS to fix the problem, this managed to fix the issue for me. Latest WP 5.7 & CPT UI.

If you need CPT working with post_format, you can add a filter to remove the parameter from the preview url like this.

add_filter('preview_post_link', 'remove_postformat_from_preview_link', 10, 2);
function remove_postformat_from_preview_link($preview_link, $post) {
    if (str_contains($preview_link, 'post_format')) {
        return preg_replace('~(\?|&)post_format=[^&]*~', '$1', $preview_link);
    }
    return $preview_link;
}

本文标签: pluginsPreview with Custom Post Type Not Working