1
function cgp_create_post($title, $name){
    $new_post = array(
        'post_title'    => $title,
        'post_type'     => 'custom-post-type',
        'post_status'   => 'publish'
    );

    $mypost_id = post_exists( $title );
    if (!$mypost_id) {
        $mypost_id = wp_insert_post( $new_post, true );
    }
    echo $mypost_id; //this was never echoed and the script abruptly stops here
    update_post_meta( $mypost_id, 'times', '1' );
}

Above snippets of my code, result is the custom post is created but the line when i test value of $mypost_id by echoing it, it never echoed anything, the script also abruptly stop at that line.

1 Answer 1

2

Apparently there is nothing wrong with my script above. There is actually a conflict with another plugin which called the same 3rd party script twice via add_action( 'save_post', 'function_name'). This double fired the 3rd party script and caused error when my script above try to do insert post.

I have turned on debug at wp-config.php by setting define('WP_DEBUG', true); define('WP_DEBUG_LOG', true);

and then solved the bugs via the error logs provided.

Your Answer

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

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