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?
- When to use Exceptions vs Error Objects vs just plain false/null
- PHP Catchable fatal error: Object of class WP_Error could not be converted to string
- WordPress “Link has expired” error on updating posts
- PHP/Manual use of images? – 2 Questions
- 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
- “Can’t use function return value in write context” error
- Error when requesting password reset email – wp authentication
- “Notice: Undefined variable: content” is showing [closed]
- Fatal error: Call to undefined method WP_Error::get_item_quantity()
- 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
- 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
- WordPress Script stops suddenly
- Auto-Select Parent Category as Primary
- A non-numeric value encountered in /wp-includes/functions.php on line 68
- Don’t insert if permalink is the same?
- fatal error call to undefined function get_header in index.php on line 1
- Use of wp_insert_post and parameters
- Headers already sent in Pluggable.php / homepage and wp-login error
- Syntax error in a shortcode function
- Warning: Illegal string offset on theme options page [closed]
- PHP if statement works in template files, but not header
- Errors after upgrading PHP to 7.4 WordPress
- PHP-warning in post-template.php and no loading content on pages
- Parse error: syntax error, unexpected ‘}’ [closed]
- Array to string conversion error in PHP 7.2 when returning user role as class
- javascript variable to wordpress php variable
- Add new post in existing categories using wp_insert_post
- PHP E_WARNING being shown despite php.ini [closed]
- get post id from wp_insert_post for get_template_part
- Generate CSV file and add data as a new wordpress custom post
- What’s wrong with this piece of code? [closed]
- PHP Helper Class to create shortcodes
- can’t get errors
- Cannot load media and I get “PHP Warning: Invalid argument supplied for foreach(“
- Fatal Error wp-settings.php on line 119
- How can I fix this code [duplicate]
- Trying to display terms from custom taxonomy within function
- how to add datas in taxonomy to post with wp_insert_post
- Too many errors on log
- Programmatically revert to backup .htaccess a possibility?
- Prevent post from being published and show error
- Replace old theme that understand old css (vcex_icon_box css_animation)
- Can’t log in to WordPress wp-admin after adding code to functions.php
- White screen after migrating site, but wp-admin works fine. Disabling all plugins, applying default theme and enabling debug mode does nothing
- Fatal error login WordPress [duplicate]
- Connecting to upstream failed
- Fatal error: wp-settings.php on line 199
- PHP Warning: mysqli_query(): after updating my websites php from 5.6 to 7.2
- WordPress Bad Request Error 400
- Reduce Stock Based on Custom Variation Field Rather than Attribute (Working Script)
- HELP: cannot log into wordpress. PHP error
- Why am I getting syntax error, unexpected ‘endwhile’ (T_ENDWHILE) on single.php
- The link you followed has expired. Please try again
- PHP error on local server install
- Site title not showing. Please help me
- Getting an empty space in up sell items
- This occurs when I open admin or front on localhost
- Is there a way to search for a missing endif?
- how to call other plugins once custom post has been inserted
- style.min.css code issue
- Adding user meta to post meta wp_insert_post() not working
- How to send logs to plugin owner for a plugin?
- Fatal Error cannot log into wordpress and website disappeared
- pages disable after wordpress update
- global $post inside plugin query messes up every new post page in wp-admin
- Importing demo data in Multisite
- Front end post submissions do not get submitted in the category
- Functions are causing errors
- Too few arguments for printf() [closed]
- Post content not showing some content
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- Catchable fatal error in appcloud free theme by Tokokoo
- Troubleshooting “loopback requests that take too long”
- 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
- How to handle PHP parse errors?
- WordPress White Screen Error
- 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
- Divi – add title to mobile menu button
- PHP – Multiple variables in insert post array
- 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
- WordPress critical error after trying to update to 6.2 – Fatal error: Allowed memory size of 268435456 bytes exhausted
- Can’t insert into a database wordpress