Mahsum Akbas
Mahsum Akbas

Reputation: 1583

wp_insert_post() function returns error

I have following php code that placed under my wordpress website. I get return 0 with the following error message:

Could not insert post into the database

My php code is:

include('/home/xxx/httpdocs/wp-blog-header.php');
$my_wp_post = array();
$my_wp_post['post_title'] = 'it is title';
$my_wp_post['post_content'] = 'it is content';
$my_wp_post['post_status'] = 'publish';
$my_wp_post['post_author'] = 1;
$my_wp_post['ping_status'] = 1;
$my_wp_post['post_category'] = array('0');
#var_dump($my_wp_post);
$post_id = wp_insert_post( $my_wp_post, true );
    if (is_wp_error($post_id)) 
    {
    $errors = $post_id->get_error_messages();
    foreach ($errors as $error) {
        echo "- " . $error . "<br />";
        }
    }

Where did I make a mistake?

Upvotes: 2

Views: 3645

Answers (1)

Mahsum Akbas
Mahsum Akbas

Reputation: 1583

i found problem. because my php file encoding is ANSI it cause some non-ascii character problems. i changed it into UTF-8 and problem is solved. Thanks for your support

Upvotes: 1

Related Questions