I had set up a custom post type on a recent project and added meta boxes to the post and post-new pages. I then wanted to have the post meta to be editable through Quick Edit and Bulk Edit. Knowing that someone, somewhere will have come up with a solution, I was pleased to find that Rachel Carden had done just that.
Her code catered for text, radio buttons and select dropdowns. Perfect, I thought, and indeed the well commented files I downloaded did the job. Sort of.
The Problem
On this particular project, I wanted to add three extra fields to the post list table. A text field and two select dropdowns. The problem I had trouble solving was when saving Bulk Edits. The code didn’t seem to cater for when only one select dropdown field was being bulk-edited. I found that, unlike the core select dropdowns, once bulk edit was clicked, there was no – No Change – option presented in the select dropdowns. This meant when the update button was clicked, all select dropdowns would update.
The Solution
The solution I came up with required adding a – No Change – option to select dropdowns only when bulk editing. By using the current_filter()
function I was able to distinguish between quick editing and bulk editing then add the appropriate input element. Like so:
$bulk = strpos(current_filter(), 'bulk') !== '' ? true : false;
When quick editing, the action used is quick_edit_custom_box
and returns false, when bulk editing, bulk_edit_custom_box
is used and returns true. It was then quite straight forward emulating core select dropdowns.