Custom Fields

It is possible for you to hook into the Bulk Edit Pro plugin to add the fields that you need to edit if you know the meta_key for the custom field.

Follow these instructions to add the custom fields to the Bulk Editor:

1. Download the free Code Snippets plugin: https://wordpress.org/plugins/code-snippets/
2. Create a Snippet with the following code (Note: If you are more comfortable with editing your functions.php you can do that instead of Code Snippets.):

function pw_bulk_edit_custom_columns( $columns ) {
    $columns[] = array(
        'name' => 'Field Name 1',
        'type' => 'text',
        'table' => 'meta',
        'field' => '_meta_key_of_field1',
        'visibility' => 'both',
        'readonly' => false,
        'sortable' => 'false'
    );

    $columns[] = array(
        'name' => 'Field Name 2',
        'type' => 'text',
        'table' => 'meta',
        'field' => '_meta_key_of_field2',
        'visibility' => 'both',
        'readonly' => false,
        'sortable' => 'false'
    );

    return $columns;
}
add_filter( 'pwbe_product_columns', 'pw_bulk_edit_custom_columns' );

For “type”, the valid options are text, currency, number, date, and checkbox.

Sorting
If you want to be able to sort by the custom field, set “sortable” to “true” in the above code and add the following code to the snippet:

function custom_pwbe_common_fields( $common_fields ) {
    global $wpdb;

    if ( isset( $_POST['order_by'] ) ) {
        if ( $_POST['order_by'] == '_meta_key_of_field1' ) {
            $common_fields .= ", (SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = post.ID AND meta_key = '_meta_key_of_field1') AS `_meta_key_of_field1`";
        }

        if ( $_POST['order_by'] == '_meta_key_of_field2' ) {
            $common_fields .= ", (SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = post.ID AND meta_key = '_meta_key_of_field2') AS `_meta_key_of_field2`";
        }
    }

    return $common_fields;
}
add_filter( 'pwbe_common_fields', 'custom_pwbe_common_fields' );

Calculated Fields
If you have a calculated field that you want to display, it will be read-only. Follow the instructions in this guide: Calculated Fields

Skip to content