0

I'm not a WordPress developer -- just a guy trying to keep things updated and writing blog posts.

If I try to publish or save the draft of a new post, I get:

A post type mismatch has been detected.

I am running WordPress 5.3.2 running the Scaffold theme.

I just updated to that version, and this problem started occurring.

Poking around this site I found a few posts with this error, but they all were about programming WordPress. I noted that it had something to do with the Theme, so I changed themes to one of the stock themes provided by WordPress, but I get the same thing no matter what I try in that area.

I disabled all my plugins, to no avail.

Can anyone help me fix my site?

ADDED: I also had trouble with Gutenberg post-update, so I deleted it.

MORE ADDED: Weird thing I noted: The Permalink button on the editor refers to my About Page.

8
  • which post IDs? do you have database access to check the corresponding row in the wp_posts table?
    – Joel M
    Commented Jan 21, 2020 at 3:48
  • If the post type is no longer registered due to changing themes or plugins then you wouldn't be able to edit those posts but i would think you would see a different message. Im wondering if the uniqueness constraint is missing from the ID column of the posts table allowing for multiple posts with the same ID. Searching WP core files for that error message may reveal more but I'm on my phone right now.
    – Joel M
    Commented Jan 21, 2020 at 3:52
  • Sorry also what's the relevant urls and what's the post type called.
    – Joel M
    Commented Jan 21, 2020 at 3:53
  • The post ID is submitted behind the scenes in a form to a url that speceifies the post type. this means that malformed HTML or misbehaving javascript could be the culprit.
    – Joel M
    Commented Jan 21, 2020 at 3:54
  • Could be due to a post type registered with invalid special characters. Should never be done but seemingly could cause similar issues.
    – Joel M
    Commented Jan 21, 2020 at 3:56

1 Answer 1

1

In my version of WordPress this error will come from line 46 of wp-admin/post.php, which has:

if ( isset( $_POST['post_type'] ) && $post && $post_type !== $_POST['post_type'] ) {
    wp_die( __( 'A post type mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 );
}

The code before that looks pretty straight forward. It just checks the database for the post object based on the post ID that is submitted with the form.

You might gain more insight by trying the following. Edit the post in question. Right click the browser and click inspect element (in Chrome). Click the "network" tab, then find the "all" sub tab. Now, leave the dev tools window open, and click Publish. An item should show up in the list called post.php. Ignore if it says post.php?action=edit etc.

Click on post.php and on the right click the Headers tab. Ensure that under "General" it says Request Method: POST. Then under Form Data, if its hard to read, click view parsed. Otherwise, it should say post_type: post. In addition you should see post_ID: {some integer}.

if post_ID or post_type is incorrect then this will cause your issue. Another thing to look out for is if there are 2 items with the same name. Check the end of the list to see if either of them is submitted again. Submitted the same index twice is fine in general but probably the second one will take precedence and it could be incorrect.

I would guess that this probably won't reveal anything. But it can show that the form data is likely being rendered properly and sent to the server properly by your web browser. Assuming nothing looks incorrect here, it's probably something server side that happens after the data is correctly submitted.

The next thing to check would be to add two lines of code above line 46. However, you have to add the code after you load the page and before you hit submit. And you'll have to remove the code afterwards otherwise you won't be able to view or save any posts.

echo '<pre>' . htmlspecialchars( print_r($_POST, true) ) . '</pre>';
exit;

if ( isset( $_POST['post_type'] ) && $post && $post_type !== $_POST['post_type'] ) {
    wp_die( __( 'A post type mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 );
}

When I hit publish, I get the following...

Array
(
    [_wpnonce] => f5557dcf89
    [_wp_http_referer] => /wp-starter/wp-admin/post.php?post=1&action=edit
    [user_ID] => 1
    [action] => editpost
    [originalaction] => editpost
    [post_author] => 1
    [post_type] => post
    [original_post_status] => publish
    [referredby] => http://localhost:8080/wp-starter/wp-admin/post.php?post=1&action=edit
    [_wp_original_http_referer] => http://localhost:8080/wp-starter/wp-admin/post.php?post=1&action=edit
    [post_ID] => 1
    [meta-box-order-nonce] => a98dcd6a27
    [closedpostboxesnonce] => 1033a61a51
    [post_title] => Hello world!

    .... (plus a bunch more)
)

This array should more or less contain the same data that was in the network tab under Form Data.

The important part is that the server is recognizing the post_ID and the post_type, and they are both valid.

It's also possible that your server is truncating the input variables to a maximum number. By default this number is quite high but if a form sends say over 1000 points of data to the server, it might be ignoring them, which if the post_type was ignored, then this will cause the error you are seeing.

2
  • That last little bit was it. The post_id value was a number bigger than BigInt...... changed them all and things started working again. THanks. Commented Jan 23, 2020 at 18:57
  • Cool, didn't think it would be that easy but glad it works now.
    – Joel M
    Commented Jan 23, 2020 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.