Telford 615787
Web Design • Beauty is in simplicity
Like on Facebook Follow on Twitter Follow on Pinterest Connect on LinkedIn

Using Bulk Edit on WP custom post types with multiple select dropdowns

Bulk Edit WP custom post type with multiple select dropdownsI 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.

by
Sid Edwards

Sid Edwards Web Designer

Sid is Proprietor of tuzongo.com with an interest in helping small and medium-sized enterprises compete with large companies. He has many years experience using coding skills with standard frameworks to create unique award winning websites. You can follow Sid on Twitter, connect on LinkedIn, Like on Facebook or circle on .
Using Bulk Edit on WP custom post types with multiple select dropdowns was last modified: October 18th, 2016 by Sid Edwards
Leave a Reply

Are you human? (required)

Find me on Google+

Latest Posts

Access

Address

Old Toll Gate, St George's
Telford Shropshire TF2 9FH
Phone: Telford 615787
Website: tuzongo.com
Email: sid@tuzongo.com

Recent Projects

  • Telford
    Telford
    TUZONGO Web Design is the proud sponsor of the Telford Group.  Open to all who wish to share our aim to celebrate...
  • The PathHeights Brand
    Branding a brand new Band
    The band’s name, The PathHeights, derives from the word Ptahites, meaning spiritual, creative beings conveying a collective conscious message. They...