Fix duplicate fields with quick_edit_custom_box hook in Wordpress


/ Published in: PHP
Save to your folder(s)

Adding custom fields to the quick edit panel in Wordpress is easy using built-in hooks. However, the hook to add fields seems to be called multiple times, adding duplicate fields to the quick edit panel. Adding this code to the top of the function being called by quick_edit_custom_box checks if the action has already been called and prevents it from being called again.

More info [here](http://wp.tutsplus.com/tutorials/extending-the-quick-edit-tool-for-taxonomy-terms/ "Extending the Quick Edit Tool for Taxonomy Terms | Wptuts+")


Copy this code and paste it in your HTML
  1. global $post;
  2.  
  3. //if post is a custom post type and only during the first execution of the action quick_edit_custom_box
  4. if ( $post->post_type != 'post' || did_action( 'quick_edit_custom_box' ) !== 1 ) return;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.