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?
- 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() is returning the correct post ID, no failure, but the post content does not get updated
- 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?
- Fatal Error relating to sessions.php
- 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
- 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
- “Undefined index” error when saving empty array with checkboxes
- Syntax error in a shortcode function
- Warning: Illegal string offset on theme options page [closed]
- customize wordpress database error page
- PHP if statement works in template files, but not header
- wp_insert_post() with HTML tags using PHP
- PHP-warning in post-template.php and no loading content on pages
- After adding my website to a new server, I keep getting a unexpected end of file error, but the file is identitcal to it’s original source
- Parse error: syntax error, unexpected ‘}’ [closed]
- Array to string conversion error in PHP 7.2 when returning user role as class
- 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
- Fatal errors to undefined function in theme 404.php file [closed]
- PHP Helper Class to create shortcodes
- How to use `wp_insert_post()` and `get_permalink()` functions?
- wordpress admin part is not accesbile after server shifting
- Fatal Error wp-settings.php on line 119
- Trying to display terms from custom taxonomy within function
- Help with accessing wp-admin page and resolving error messages
- Blog suddenly shows Archive instead of index page
- Programmatically revert to backup .htaccess a possibility?
- Prevent post from being published and show error
- Illegal string offset in PHP function in via Theme Customizer
- 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
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- I am having errors with checkout on wordpress
- How can I pass php code as a content while publishing a post
- Intermittent 503 Service Unavailable Error
- Fatal error: wp-settings.php on line 199
- Reduce Stock Based on Custom Variation Field Rather than Attribute (Working Script)
- Trying to get property ‘ID’ and ‘post_author’ of non-object error
- HELP: cannot log into wordpress. PHP error
- The link you followed has expired. Please try again
- PHP error on local server install
- Site title not showing. Please help me
- Meta inserted through wp_insert_post gets messed up
- PHP Error in WordPress Theme
- WordPress database error only while loading page for 1st time
- This occurs when I open admin or front on localhost
- how to call other plugins once custom post has been inserted
- How to send logs to plugin owner for a plugin?
- WordPress 3.0 PHP Error – notice WordPress_product_Type was called incorrectly
- Importing demo data in Multisite
- WordPress error on my website
- Front end post submissions do not get submitted in the category
- Changed URl in General Settings now WordPress site doesnt work
- 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
- Troubleshooting “loopback requests that take too long”
- Query Concatenation
- What does that mean: cannot use a scalar value as an array [closed]
- problem with php function error
- How to handle PHP parse errors?
- WordPress White Screen Error
- Please help! Parse error: syntax error, unexpected ‘
- Front-end major break after upgrade PHP 8.0 [closed]
- PHP warning $post->ID is null
- 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
- “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()’
- Undefined constant ABSPATH
- PHP Warning: Undefined array key “HTTP_REFERER”
- Warning: Undefined variable $post_id
- There has been a critical error on this website – wordpress issue after upgrading PHP