Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Adding post types to Quick Edit plugin WordPress


I want to add post_type to the Quick Edit panel so that I can bulk edit custom post types using WP's built-in multi-edit interface. The 3 or so plugins that edit post types don't let me change post type based on custom taxonomy term, so I need to make my own.

Attached is a commented version of the Shibashake tutorial [[LINK href=""]]here[[/LINK]] which adds an edit page column and a Quick Edit drop-down menu for a new meta field. I need to edit this to replace meta field with post type. Most of the changes are pretty straightforward, like these:

To display post type in the column, change get_post_meta() to get_post_type():
// get_post_meta( $id, 'post_widget', TRUE); // old
get_post_type( $id ); //new

For the dropdown, changing the existing code to this:
$post_types = get_post_types( (array) $args, 'objects' );
foreach ($post_types as $post_type) {
echo "<option class='widget-option' value='$post_type'>$post_type</option>\n";

On save, changing update_post_meta() to set_post_type()
// update_post_meta( $post_id, 'post_widget', $widget_set_id);
set_post_type( $post_id, $post_type);

But there are a few pieces I'm not as sure about, so I'm putting it on WPQuestions. In summary, I need to change the attached code from a meta field Quick Edit to a post type Quick Edit, and I want it to work on all post types instead of just Posts.

Answers (1)


Christianto answers:


please try file attach..
put it on your functions.php

In the tutorial link there are error on js (item selected won't updated), so I use my own method, its also support posts/page and custom post type..

I try it on my localhost and it work..
Let me know the result in your site..


web559 comments:

Thanks! This works for Quick Editing individual posts, but the dropdown does not appear when I bulk edit. Do you know what needs to be changed to allow it to bulk edit?

Christianto comments:


We can show post type field on bulk editing, but the only way to saved the value properly is by editing and adding small code on wordpress core post.php (<em>wp-admin/includes/post.php</em>), which I think its not practical.

I tried different action including 'save_post' action in the tutorial provided but it failed to save. I looked at the function workflow and the only action run is 'save_post'.

If you think that editing wordpress core post.php is ok, I will give the snippet and updating the code..

The only drawback is you have to check post.php if you update your wordpress installation and edit it if the file replaced.

web559 comments:

So there are no hooks that you can add set_post_type into for the bulk edit? If editing post.php is the only way to get multi-edit to work, that's fineā€”can you post the code?

Christianto comments:

please try the code attach..

Change file post.php (<em>wp-admin/includes/post.php</em>) on line 254 there is function bulk_edit_posts() that use to process the bulk editing posts.

at the end of function (line 364) there are code to processing the sticky post, the code look like this..

if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
if ( 'sticky' == $post_data['sticky'] )
stick_post( $post_ID );
unstick_post( $post_ID );

add this code after sticky code..

if ( isset( $post_data['post_type_set'] ) && $post_data['post_type_set'] != '-1' && current_user_can( $ptype->cap->edit_others_posts ) ) {
set_post_type( $post_ID, $_REQUEST['post_type_set']);

You can look at the code if you think there are hook that can be use, but I looked at the code and the only hook that run is 'save_post' which run inside wp_update_post() on line 362..