0

I have a website built with WordPress and I've been using the code snippets plugin in order to automate some backend stuff. I've been trying to create posts automatically but every time I run the snippet the post is created, however my website crashes, displaying the "A critical error has occured on your website" screen and and the rest of the snippet is not executed. This is the content of the snippet in question:

$new_page_args = array(
    'post_type'     => 'product',  //the custom type of the post I'm trying to create
    'post_title'    => 'My new product',
    'post_status'   => 'publish',
    'post_author'   => 1
);
    
$post_id = wp_insert_post($new_page_args, true); //this should create the post and return its id, 
                                                 //or a wp_error if something goes wrong

The problem is that since the snippet crashes immediately after executing wp_insert_post() I have no way of printing the error and figuring out what's wrong. Any input on how to fix this or even how to go about debugging it would be very welcome.

2
  • If you turn on WP_DEBUG, you should see more detail about what went wrong, which will help you narrow down the problem. – Pat J Apr 11 at 21:40
  • 2
    Thanks a lot! I did as you said and apparently the issue is caused by an uncaught error in my HubSpot for WooCommerce plugin, I deactivated the plugin for now and will reach out to them to report the bug. – Qwello Lee Apr 12 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.