I am trying to make a form that auto posts without needing to be signed in. So far I'm testing with dummy data, but I'm running into trouble with the add_post_meta part. It seems to only be adding 1 character (the 2nd one for some reason). This is my code:

$my_post = array(
    'post_title' => wp_strip_all_tags('testing'),
    'post_author' => 5,
    'post_content' => 'This is my post.',
    'post_category' => array( 135 ),
    'post_status' => 'draft',
    'post_type' => 'portal',

$post_id = wp_insert_post($my_post);

add_post_meta($post_id, 'portal_tl_name', 'karen');
add_post_meta($post_id, 'portal_tl_brokerage', 'coquitlam');

When I load the page with this script, it add's the post, but in the 2 sections with meta data, I'm only seeing:


I'm not sure why. Am I missing something?

  • 1
    Your code looks fine, and it isn't happening to me when I run the exact same code in my install. What other code is on this page? How are you displaying the meta data - is it possible that the issue is occuring there? – Tim Malone Mar 9 '16 at 1:37
  • @TimMalone I'm using the Post Meta plugin to create the portal post type. And then adding custom field textboxes to the editor for that post type. That is where I only see 1 character showing up. – Keryn Gill Mar 9 '16 at 16:58

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.