开发者

insert row in wordpress table with wpdb class

I'm working on this little plugin that enables a user to submit a post on my website.

if (!isset($wpdb))
    $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);

$wpdb->insert(
    $wpdb->prefix . 'posts',
    array(
        'post_title' => 'testerrrr',
        'post_author' => '1',
        'post_content' => 'geen content aja',
    'post_status' => 'publish'
    )
);

The above code isn't adding a new row to the table. (I also tried with $wpdb->wp_posts) And it doesn't give me an error neither (error reporting is turned on thou开发者_运维问答gh) Are there maybe other fields that I'm obliged to use in the array, or am I doing something else wrong?

Thanks!


As TheDeadMedic stated, this can be achieved with wp_inser_post();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜