I have the following code, I am attempting to insert a new post with the 2 meta fields attached, the post is being inserted but the meta isn't there.

Can't seem to spot anything wrong here, so what's going wrong?

$title = 'test';
$test1 = 'test';
$test2 = 'test';

$new_post = array(
    'post_title'    => wp_strip_all_tags( $title ),
    'post_status'   => 'publish',
    'post_type'     => 'post',
    'meta_input'    => array(
        '_test1'    => $test1,
        '_test2'    => $test2,

wp_insert_post( $new_post );
  • How are you retrieving the meta to see if it was added or not? Assign wp_insert_post to a variable and var_dump it and see what's returned. – Steve North Mar 21 '18 at 19:39
  • I am looking in the database, I'm not in front of my computer right now but IDs expect to get the post ID as it does insert it, just no post meta – bigdaveygeorge Mar 21 '18 at 19:42
  • Looking in the wp_postmeta table right? – Steve North Mar 21 '18 at 19:51
  • Yep in the post meta table – bigdaveygeorge Mar 21 '18 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.