• Hi!

    I′m having some trouble with saving custom post type content when going from future to publish. When I set a post to be published in the future, it will be published, but all my custom field contents will be erased. Except the title, which must mean that I′m doing something wrong saving the custom fields.

    Thankful for all help I can get! (first time posting in the forum)

    Here is my functions.php (it′s in a child theme). You will find two CPT, both which I am having trouble with.

    <?php
    
    function create_permadi_com_post_type()
    {
    	register_post_type('veckansblommor',
    		array(
    			'labels' => array(
    			'name' => __('Veckans blommor/tema'),
    			'singular_name' => __('Veckans blommor/tema'),
    		 ),
    		'public' => true,
    		'publicly_queryable' => true,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => array('slug'=>'','with_front'=>false),
    		'rewrite' => true,
    		'capability_type' => 'post',
    		'hierarchical' => false,
    		'menu_position' => 9,
    		'supports' => array('title'),
    		)
    
    	);
    
    register_post_type('slide',
    		array(
    			'labels' => array(
    			'name' => __('Slide'),
    			'singular_name' => __('Slide'),
    		 ),
    		'public' => true,
    		'publicly_queryable' => true,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => array('slug'=>'','with_front'=>false),
    		'rewrite' => true,
    		'capability_type' => 'post',
    		'hierarchical' => false,
    		'menu_position' => 9,
    		'supports' => array('title', 'thumbnail'),
    		)
    
    	);
    
    }
    
    function create_permadi_com_metaboxes()
    {
    	add_meta_box("book-form-meta-box", "Veckans blommor", "init_permadi_com_book_type_metaboxes", "veckansblommor");
    	add_meta_box("book-form-meta-box", "Slide", "init_permadi_com_book_type_metaboxes2", "slide");
    
    }
    
    function save_permadi_com_metaboxes($postId, $post=null)
    {
    	if ($post->post_type=="veckansblommor")
    	{ 
    
              // check autosave
            if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
                return $post_id;
            }
    
    		update_post_meta($postId, "veckanstema", $_POST['veckanstema']);
    		update_post_meta($postId, "veckansblommor1", $_POST['veckansblommor1']);
    		update_post_meta($postId, "veckansblommor2", $_POST['veckansblommor2']);
    		update_post_meta($postId, "veckansblommor3", $_POST['veckansblommor3']);
    		update_post_meta($postId, "veckansblommor4", $_POST['veckansblommor4']);
    		update_post_meta($postId, "veckansblommor5", $_POST['veckansblommor5']);
    		update_post_meta($postId, "veckansblommor6", $_POST['veckansblommor6']);
    		update_post_meta($postId, "veckansblommor7", $_POST['veckansblommor7']);
    		update_post_meta($postId, "veckansblommor8", $_POST['veckansblommor8']);
    		update_post_meta($postId, "veckansblommor9", $_POST['veckansblommor9']);
    		update_post_meta($postId, "veckansblommor10", $_POST['veckansblommor10']);
    
    				}
    					if ($post->post_type=="slide")
    	{ 
    
              // check autosave
            if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
                return $post_id;
            }
    
    		update_post_meta($postId, "slidetext", $_POST['slidetext']);
    		update_post_meta($postId, "slidel?nk", $_POST['slidel?nk']);
    
    				}
    }
    
    function init_permadi_com_book_type_metaboxes()
     {
      global $post;
      $bookCustomData=get_post_custom($post->ID);
      $veckanstema = $custom["veckanstema"][0];
      $veckansblommor1 = $custom["veckansblommor1"][0];
      $veckansblommor2 = $custom["veckansblommor2"][0];
      $veckansblommor3 = $custom["veckansblommor3"][0];
      $veckansblommor4 = $custom["veckansblommor4"][0];
      $veckansblommor5 = $custom["veckansblommor5"][0];
      $veckansblommor6 = $custom["veckansblommor6"][0];
      $veckansblommor7 = $custom["veckansblommor7"][0];
      $veckansblommor8 = $custom["veckansblommor8"][0];
      $veckansblommor9 = $custom["veckansblommor9"][0];
      $veckansblommor10 = $custom["veckansblommor10"][0];
    
      ?>
    
    <p><label>Beskrivning av veckans tema</label></p>
    <textarea cols="80" rows="7" name="veckanstema"><?php echo $bookCustomData['veckanstema'][0]; ?></textarea>
    
    <p><label>Veckans blomma 1</label></p>
    <textarea cols="40" rows="2" name="veckansblommor1"><?php echo $bookCustomData['veckansblommor1'][0]; ?></textarea>
    
    <p><label>Veckans blomma 2</label></p>
    <textarea cols="40" rows="2" name="veckansblommor2"><?php echo $bookCustomData['veckansblommor2'][0]; ?></textarea>
    
    <p><label>Veckans blomma 3</label></p>
    <textarea cols="40" rows="2" name="veckansblommor3"><?php echo $bookCustomData['veckansblommor3'][0]; ?></textarea>
    
    <p><label>Veckans blomma 4</label></p>
    <textarea cols="40" rows="2" name="veckansblommor4"><?php echo $bookCustomData['veckansblommor4'][0]; ?></textarea>
    
    <p><label>Veckans blomma 5</label></p>
    <textarea cols="40" rows="2" name="veckansblommor5"><?php echo $bookCustomData['veckansblommor5'][0]; ?></textarea>
    
    <p><label>Veckans blomma 6</label></p>
    <textarea cols="40" rows="2" name="veckansblommor6"><?php echo $bookCustomData['veckansblommor6'][0]; ?></textarea>
    
    <p><label>Veckans blomma 7</label></p>
    <textarea cols="40" rows="2" name="veckansblommor7"><?php echo $bookCustomData['veckansblommor7'][0]; ?></textarea>
    
    <p><label>Veckans blomma 8</label></p>
    <textarea cols="40" rows="2" name="veckansblommor8"><?php echo $bookCustomData['veckansblommor8'][0]; ?></textarea>
    
    <p><label>Veckans blomma 9</label></p>
    <textarea cols="40" rows="2" name="veckansblommor9"><?php echo $bookCustomData['veckansblommor9'][0]; ?></textarea>
    
    <p><label>Veckans blomma 10</label></p>
    <textarea cols="40" rows="2" name="veckansblommor10"><?php echo $bookCustomData['veckansblommor10'][0]; ?></textarea>
    
    <?php
    }
    
    function init_permadi_com_book_type_metaboxes2()
     {
      global $post;
      $bookCustomData=get_post_custom($post->ID);
      $slidetitel = $custom["slidetitel"][0];
      $slidetext = $custom["slidetext"][0];
      $slidel?nk = $custom["slidel?nk"][0];
    
      ?>
    
    <p><label>Slidebeskrivning</label></p>
    <textarea cols="80" rows="2" name="slidetext"><?php echo $bookCustomData['slidetext'][0]; ?></textarea>
    
    <p><label>Slidel?nk</label></p>
    <textarea cols="80" rows="2" name="slidel?nk"><?php echo $bookCustomData['slidel?nk'][0]; ?></textarea>
    
    <?php
    }
    
    function veckansblommor_edit_columns($columns){
      $columns = array(
        "cb" => "<input type=\"checkbox\" />",
        "title" => "Veckans tema",
        "veckanstema" => "Beskrivning",
        "date" => "Datum",
    
      );
    
      return $columns;
    }
    function veckansblommor_custom_columns($column){
      global $post;
    
      switch ($column) {
        case "veckanstema":
          $custom = get_post_custom();
          echo $custom["veckanstema"][0];
          break;
    
      }
    }
    
    function slide_edit_columns($columns){
      $columns = array(
        "cb" => "<input type=\"checkbox\" />",
        "title" => "Slidetitel",
        "slidetext" => "Beskrivning",
        "slidel?nk" => "L?nk",
        "date" => "Datum",
    
      );
    
      return $columns;
    }
    function slide_custom_columns($column){
      global $post;
    
      switch ($column) {
        case "slidetext":
          $custom = get_post_custom();
          echo $custom["slidetext"][0];
          break;
         case "slidel?nk":
          $custom = get_post_custom();
          echo $custom["slidel?nk"][0];
          break;
      }
    }
    add_action('publish_future_post', 'save_permadi_com_metaboxes', 1);
    add_action('init', 'create_permadi_com_post_type');
    add_action('admin_init', 'create_permadi_com_metaboxes');
    add_action('wp_insert_post', 'save_permadi_com_metaboxes', 10, 2);
    add_action("manage_posts_custom_column",  "veckansblommor_custom_columns");
    add_filter("manage_edit-veckansblommor_columns", "veckansblommor_edit_columns");
    add_action("manage_posts_custom_column",  "slide_custom_columns");
    add_filter("manage_edit-slide_columns", "slide_edit_columns");
    
    add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
    
    function my_custom_dashboard_widgets() {
    global $wp_meta_boxes;
    
    wp_add_dashboard_widget('custom_help_widget', 'V?lkommen till Grow by Kelli & Caisa - adminpanelen', 'custom_dashboard_help');
    }
    
    function custom_dashboard_help() {
    echo '<p>Detta ?r panelen fr?n vilken du kan administrera hela webbplatsen. I panelen hittar du Teknisk support, Bes?ksstatistik fr?n Google Analytics, F?rs?ljningsstatistik och ?vrig anv?ndbar information om webbplatsen.</p>';
    echo '<h4>Funktioner p? GrowEco.se</h4>';
    echo '<p>Med GrowEco.se administrationspanel kan du administrera hela webbplatsen. Du kan hantera:
    Produkter, Produktkategorier, Produktvariationer, Kuponger, Best?llningar, Betalningar, Kunder, Bloggen, Veckans tema, Statiska sidor, Media, Anv?ndare och Statistik.</p>';
    echo '<p>Om du ?nskar fler funktioner till din webbplats eller beh?ver tekniskt support, v?nligen anv?nd kontaktformul?ret nedan.</p>';
    
    }
    
    // Create the function to use in the action hook
    function example_remove_dashboard_widgets() {
    	remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
    	remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
    	remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' );
    	remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
    	remove_meta_box( 'dashboard_secondary', 'dashboard', 'side' );
    	remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
    	remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
    	remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
    } 
    
    // Hoook into the 'wp_dashboard_setup' action to register our function
    add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );
    
    //remove wp e-commerce stuff from head
    add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
    
    function my_deregister_styles() {
      wp_deregister_style( 'wpsc-product-rater' ); // prevents the product_rater.css from being loaded
      wp_deregister_style('wp-e-commerce-dynamic'); // prevents the dynamic css everyone's talking about in this thread https://getshopped.org/forums/topic.php?id=5638
      wp_deregister_style( 'wpsc-thickbox' ); // prevents the thickbox CSS from being loaded
      wp_deregister_script( 'wpsc-thickbox' ); // prevents the thickbox script from being loaded from being loaded
      wp_deregister_script('jquery-rating'); // prevents ratings script from being loaded
      remove_action('wp_head', 'wpsc_product_list_rss_feed'); // prevents RSS feed from being loaded
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ejubbicic

    (@ejubbicic)

    Got it!

    I removed the add_action call in the bottom and put it together with the function like this:

    add_action(‘save_post’, ‘save_details’);
    function save_details() {

    And it worked!

    Thread Starter ejubbicic

    (@ejubbicic)

    Or so I thought… Worked for post that were already created, not for new posts…
    Now its not even saving posts…

    Please help!

    Thread Starter ejubbicic

    (@ejubbicic)

    global $post; DID IT! Yaaay!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom post type Future to Publish’ is closed to new replies.