• I have pieced together stuff I Have working with what I read about creating forms. I have all of the info here and the form works and creates a post. The issue is that the meta data I need from the form is not being saved I just get _wpas_done_all on the meta database.

    [Excessive code removed – please see the forum guidelines about posting code – http://codex.wordpress.org/Forum_Welcome#Posting_Code – that’s too much and it was mangled by the forums since you did not use the code buttons ]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator t-p

    (@t-p)

    if I understand your question, check with plugins, for example:

    http://wordpress.org/extend/plugins/contact-form-7/

    http://wordpress.org/plugins/form-maker/

    http://wordpress.org/plugins/formbuilder/

    there are more plugins in the plugins repo

    Thread Starter jone3fingers

    (@jone3fingers)

    Tara, that does not help. I made a mistake not using the code link. here is my code: It is not a plugin.

    <?php
    /* Template Name: Add Artist */ 
    
    get_header();
    ?> 
    
    <div id="primary">
    <div id="content" role="main"> 
    
    <!-- New Post Form -->
    
    <div id="postbox">
    
    <form id="new_post" name="new_post" method="post" action="">
    
    <label for="title">Artist/Band Name</label><br />
    <input type="text" id="title" value="" tabindex="1" size="20" name="title" />
    
    <label for="wbd_description_details_bio">Bio</label><br />
    <textarea id="wbd_description_details_bio" tabindex="3" name="wbd_description_details_bio" cols="50" rows="6"></textarea>
    
    <label for="wbd_artist_details_datestart">Year Band Formed</label> ;
    <input type="text" id="wbd_artist_details_datestart" name="wbd_artist_details_datestart" value="" />
    
     <label for="wbd_artist_details_origin">Home Town</label>
     <input type="text" id="wbd_artist_details_origin" name="wbd_artist_details_origin" value="" />
    
    <label for="wbd_artist_details_label">Recording Label </label>
    <input type="text" id="wbd_artist_details_label" name="wbd_artist_details_label" value="" />
    
    <label for="wbd_artist_details_links">Website</label>
    <input type="text" id="wbd_artist_details_links" name="wbd_artist_details_links" value="" />
    
     <label for="wbd_artist_details_youtubeid">YouTube Video ID</label> '
     <input type="text" id="wbd_artist_details_youtubeid" name="wbd_artist_details_youtubeid" value="" />
    
    <label for="wbd_artist_details_grpmembers">Band Members</label>
    <textarea  id="wbd_artist_details_grpmembers" tabindex="3" name="wbd_artist_details_grpmembers" cols="25rows="6" ></textarea>
    
    <p><label for="post_tags"></label>
    
    <input type="hidden" value="" tabindex="5" size="16" name="post_tags" id="post_tags" /></p>
    
    <p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>
    
    <input type="hidden" name="page" id="page" value="< ? php echo $post->ID; ? >"/>
    
    <input type="hidden" name="action" value="post" />
    
    <?php wp_nonce_field( 'new-post' ); ?>
    
    </form>
    
    </div>
    
    <!--// New Post Form -->
    
    <?php
    
    if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {
    	// Do some minor form validation to make sure there is content
    	if (isset ($_POST['title'])) {
    		$title =  $_POST['title'];
    
    	} else {
    		echo 'Please enter a title';
    	}
    		$tags = $_POST['post_tags'];
    
    	// Add the content of the form to $post as an array
    
    	$post = array(
    		'post_title'	=> $title,
    		'post_content'	=> ' ',
    		'post_category'	=> $_POST['cat'],  // Usable for custom taxonomies too
    		'tags_input'	=> $tags,
    		'post_status'	=> 'publish',			// Choose: publish, preview, future, etc.
    		'post_type'	=> 'wbd_artist'  // Use a custom post type if you want to
    	);
    	wp_insert_post($post);  // Pass  the value of $post to WordPress the insert function
    // http://codex.wordpress.org/Function_Reference/wp_insert_post
    global $wpdb;
    
        $posted_datestart = sanitize_text_field( $_POST['wbd_artist_details_datestart'] );
      add_post_meta($post_ID, $meta, '_wbd_artist_details_datestart', $posted_datestart, true);
    
       $posted_origin = sanitize_text_field( $_POST['wbd_artist_details_origin'] );
      add_post_meta($post_ID, '_wbd_artist_details_origin', $posted_origin, true);
    
      $posted_label = sanitize_text_field( $_POST['wbd_artist_details_label'] );
      add_post_meta($post_ID, '_wbd_artist_details_label', $posted_label, true);
    
      $posted_grpmembers = sanitize_text_field($_POST,'wbd_artist_details_grpmembers_');
      add_post_meta($post_ID, '_wbd_artist_details_grpmembers', $posted_grpmembers, true);
    
      $posted_links = sanitize_text_field($_POST,'wbd_artist_details_links_');
      add_post_meta($post_ID, '_wbd_artist_details_links', $posted_links, true);
    
      $posted_youtubeid = sanitize_text_field( $_POST['wbd_artist_details_youtubeid'] );
      add_post_meta($post_ID, '_wbd_artist_details_youtubeid', $posted_youtubeid, true);
    
    $posted_description = sanitize_text_field( $_POST['wbd_description_details_bio'] );
      add_post_meta($post_ID, '_wbd_description_details_bio', $posted_description, true);
    
    } // end IF
    
    // Do the wp_insert_post action to insert it
    do_action('wp_insert_post', 'wp_insert_post');
    
    ?>
    </div><!-- #content -->
    </div><!-- #primary -->
    <?php get_footer(); ?>

    Moderator t-p

    (@t-p)

    Instead of reinventing the wheel per sey, I suggested some plugin if they can work for you.

    Thread Starter jone3fingers

    (@jone3fingers)

    I tried the plugin route first.
    They don’t make a new post and add to the meta at the same time.

    It is easier to write my own form and it all works except the meta part. I am sure I am just missing a line or two that is needed.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Meta is not saving’ is closed to new replies.