Support » Plugins » Hacks » Post meta in Custom post type, deleted by quick edit…

Viewing 3 replies - 1 through 3 (of 3 total)
  • Regis

    (@regiswordpress)

    Also, when I save data in the ‘Edit’ section, if deletes the data I saved in the ‘Quick Edit’ section…. like page hierarchy…

    Maybe the solution here will help..
    http://core.trac.wordpress.org/ticket/13197

    And another similar ticket.
    http://core.trac.wordpress.org/ticket/14192

    Googled with the following (incase you’re wondering how i found the information).
    site:http://core.trac.wordpress.org custom post type quick edit

    Regis

    (@regiswordpress)

    Thank you Marc. I found out was I was doing wrong — my nonce was badly named. But in the meantime I discovered something else. After setting a page hierarchy in the quick edit mode, I would loose the info when saving in the full edit mode. I’d created a custom post type with the option ‘hierarchical’ set to ‘true’, but I had not added support for ‘page-attributes’. So I guess that when I updated my post from the full edit mode, the hierarchy info was overwritten as empty… here is my updated code, working like a charm:

    // the custom post type declaration:
    $custom_args = array(
    	'labels' => array(
    	'name' => __( 'Things' ),
    	'singular_name' => __( 'Thing' ),
    	'add_new' => _x('Add New', 'Thing'),
    	'add_new_item' => __('Add New Thing'),
    	'edit_item' => __('Edit Thing'),
    	'new_item' => __('New Thing'),
    	'view_item' => __('View Thing'),
    	'search_items' => __('Search Things'),
    	'not_found' =>  __('No Things found'),
    	'not_found_in_trash' => __('No Things found in Trash'),
            'parent_item_colon' => ''
    	),
       'public' => true,
       'publicly_queryable' => true,
       'show_ui' => true,
       'query_var' => true,
       'rewrite' => true,
       'capability_type' => 'post',
       'hierarchical' => true,
       'menu_position' => 9,
       'supports' =>array('title','editor','author','thumbnail','excerpt','comments', 'page-attributes') );
    register_post_type ('things', $custom_args );

    I have also added a function to sanitize the input from the user.

    function save_options(){
    [...]
    update_post_meta($post->ID, "textsubtitle",cleanInput( $_POST["textsubtitle"], 'text') );
    update_post_meta($post->ID, "textauthor", cleanInput($_POST["textauthor"],'text') );
    update_post_meta($post->ID, "textshowchildren", cleanInput( $_POST["textshowchildren"], 'checkbox') );
    update_post_meta($post->ID, "textforceprocess", cleanInput( $_POST["textforceprocess"], 'checkbox') );
    update_post_meta($post->ID, "textclearformat", cleanInput( $_POST["textclearformat"], 'checkbox') );
    update_post_meta($post->ID, "subtexttitle", cleanInput( $_POST["subtexttitle"], 'text') );
    update_post_meta($post->ID, "subtextauthor", cleanInput( $_POST["subtextauthor"],'text') );</p>
    <p>return $_POST; //I am still not sure why or if I have to
                   // return anything here...
    }

    and finally, my very simple function to verify input:

    function cleanInput( $input, $type ) {
    	global $allowedposttags;
    	$cleanInput = false;
    	switch ($type) {
    	  case 'text':
    	    $cleanInput = wp_filter_nohtml_kses ( $input );
    	    break;
              case 'checkbox':
                $input === 'on'? $cleanInput = 'on' : $cleanInput = '';
    	    break;
              case 'html':
                $cleanInput = wp_kses( $input, $allowedposttags);
    	    break;
    	default:
    	    $cleanInput = false;
    	    break;
    	}
    	return $cleanInput;
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post meta in Custom post type, deleted by quick edit…’ is closed to new replies.