Just add this code
$post_id = wp_insert_post($arg);
if(!is_wp_error($post_id)){
//the post is valid
}else{
//there was an error in the post insertion,
echo $post_id->get_error_message();
}
Related Posts:
- WordPress won’t display errors at all
- kali php problem [closed]
- How to update custom fields using the wp_insert_post() function?
- Should I use spl_autoload_register() in my plugin?
- WP-CLI – Selecting PHP version
- error_log() output for print_r() appearing on page
- When to use Exceptions vs Error Objects vs just plain false/null
- Hide php Notices in Dashboard
- PHP Catchable fatal error: Object of class WP_Error could not be converted to string
- Upgrading PHP version results in “Use of undefined constant WP_CONTENT_DIR” warning?
- WSOD but WP_DEBUG not giving any errors
- WordPress “Link has expired” error on updating posts
- PHP/Manual use of images? – 2 Questions
- get_the_content if it contains multiple lines it results in SyntaxError
- Set Primary category using the Yoast SEO plugin
- Notice: Constant already defined in wp-config.php on (non-existent) line?
- “Maximum function nesting level of ‘100’ reached” after adding a new filter
- How to resolve error “Cookies are blocked due to unexpected output.”?
- error_log is not working as expected in functions.php file
- Enable errors PHP WordPress 5.2
- “Can’t use function return value in write context” error
- Fatal error: Call to undefined function wpsc_cart_item_count()
- Why when I instantiate wp_error in a validation method my user registration method stops working?
- Error when requesting password reset email – wp authentication
- “Notice: Undefined variable: content” is showing [closed]
- After upgrading to PHP 7.0 my contact form outputs error
- apache cpu over 70% on localhost
- Fatal error: Call to undefined method WP_Error::get_item_quantity()
- Does WordPress have a built in reference to the PHP version its running under? [closed]
- Can WordPress email the admin about PHP errors, while hiding them from the site?
- wp_insert_post not working
- White Screen of Death – wp-admin
- Ajax return code 400
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- WordPress 5 WP REST routes – No errors
- Can’t get wp_insert_post to work
- How to find error in my code when the error message is pointing to WP core file?
- get_term_link() returns correct – But illogical error-messages disturb
- Fatal Error relating to sessions.php
- PHP Warning: Attempt to read property “term_id” on bool
- Mute Debug Messages from Plugins
- WordPress Script stops suddenly
- Auto-Select Parent Category as Primary
- A non-numeric value encountered in /wp-includes/functions.php on line 68
- Error on wp_default_style After upgrade to php 7
- wp_ob_end_flush_all and wp_suspend_cache_addition()
- Don’t insert if permalink is the same?
- Front end post submissions do not get submitted in the category
- Headers Already Sent
- Changed URl in General Settings now WordPress site doesnt work
- Functions are causing errors
- Too few arguments for printf() [closed]
- syntax error unexpected ‘}’ at 364 line
- Post content not showing some content
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- WP white screen of death after duping a site that works fine on same server
- Catchable fatal error in appcloud free theme by Tokokoo
- Troubleshooting “loopback requests that take too long”
- Data inserted in database, but ajax calls error function
- upload images on front by user using form
- Parse error: syntax error, unexpected ‘}’ in C:\wamp64\www\Proiect\aplicatie\user_check.php on line 18 [closed]
- Query Concatenation
- WP Debug enabled Undefined index error in a widget
- php 7.0 update to 7.1 and at least 7.2
- What does that mean: cannot use a scalar value as an array [closed]
- problem with php function error
- How to handle PHP parse errors?
- PHP warning Invalid argument supplied for foreach() on custom page template
- WordPress White Screen Error
- Please help! Parse error: syntax error, unexpected ‘
- Not able to see the error [closed]
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- Front-end major break after upgrade PHP 8.0 [closed]
- Need help with Deprecated: Non-static error when update PHP 7.4 -> 8.1 with Dyad 2 theme
- PHP warning: Undefined array key 2 in feed.php
- PHP warning $post->ID is null
- Divi – add title to mobile menu button
- PHP – Multiple variables in insert post array
- Getting invalid user ID error when creating a new user with wp_insert_user
- Execute multiple PHP Snippets causes error?
- Can’t send form data to wpdb when URL has query string
- Use of undefined constant issue
- WordPress 6.1.1 shows deprecated errors with PHP 8.1 & 8.2
- I can’t log into my website , it says “Error: Cookies are blocked due to unexpected output”
- Error when loading Dashboard
- WordPress critical error after trying to update to 6.2 – Fatal error: Allowed memory size of 268435456 bytes exhausted
- WordPress @include( ‘template-config.php’ );
- Can’t insert into a database wordpress
- “Unexpected response from server” error when trying to upload any .mp4 file over 100MB
- taxonomy pages returning “NULL” when running default WordPress function ‘get_queried_object()’
- Error message not appearing in error email or in the error log
- Undefined constant ABSPATH
- PHP Warning: Undefined array key “HTTP_REFERER”
- PHP Warning: Undefined array key “VirtualHostSubMenu” in index.php
- Headers already sent error
- Why PHP Parse unmachet after update to PHP8?
- Warning: Undefined variable $post_id
- “Object-cache.php” disables wp_cron and even disables my entire site, and keeps reappearing by itself again after I delete it
- PHP Fatal error: Uncaught TypeError: Cannot access offset of type string on string in Stack trace:\n#0 [internal function]: img_caption_shortcode()
- Facing 503 error on PHP files after deleting hidden files from the root folder