How to break wp_insert_post operation with an error (1 post)

  1. orgzchaos
    Posted 2 years ago #

    I have researched on this a lot but mostly getting stuff about applying hacks etc. I have added a new condition in wp_insert_post as below which checks for a particular title and stops the post from being inserted to the database if the condition is met.

    if ( empty($post_type) )
    		$post_type = 'post';
    	if ( empty($post_status) )
    		$post_status = 'draft';
    	if ($post_title == 'XYZ') {
       return  new WP_Error('broke', __("I've fallen and can't get up"));

    Hence if the title of my post is XYZ then the post will not be published. It works fine but I still get the Post Published message. I am looking to replace this message with an error message. Anyone can help me out with this?


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.