• On my website i’ve built a plugin.
    When the database grows everything keeps up to speed, except for 1 wp_insert_post() rule. It takes over 6 seconds to insert that post.

    When i change the post_type from ‘message’ to ‘messages’ it works again within a second. So i think it has to do with the database.

    Any ideas on how to fix this?

    This is the code:

    $id = wp_insert_post(array(		'post_type' 		=> 	'message',
    									'post_status'		=>	'private',
    									'post_title'			=>	'message',
    									'post_parent'		=>	$elementid,
    									'post_content'		=>	addslashes(htmlentities($value)),
    									'post_author'		=> $senderid
    								));
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Is “message” how the post type is actually registered? Is there a separate “messages” type as well? If not, I’m surprised one works at all. Using an unregistered post type would explain why it’s so time consuming.

    The correct post type value can be discerned from the post type’s list table URL in WP admin, whatever follows edit.php?post_type=

    If you have a huge number of post table records (many many hundreds), that would explain overall slowness, but not if it’s only for a specific post type. For that, use the query monitor plugin to learn what queries are used to insert a post. The nature of the SQL itself could be a clue. Also, if a large number of post meta and taxonomy term data needs to be saved, that will also extend the time required.

Viewing 1 replies (of 1 total)
  • The topic ‘wp_insert_post slow with specific post_type’ is closed to new replies.