WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've added Archived bulk Action to my CPT, but my problem is that everything work fine only if we select the action in the second dropdown.

That's how i've added the new Bulk Action

add_action('admin_head', 'add_bulk_action');
function add_bulk_action() {
    global $wp_list_table;
    $current_screen = get_current_screen();

    if($current_screen->id == 'edit-programmation') {
            $wp_list_table->_actions = array_merge(
            array( 'archive' => __( 'Archiver' ) )

And my custom bulk action verification

add_action('load-edit.php', 'custom_bulk_action');
function custom_bulk_action() {
global $typenow;
$post_type = $typenow;

if($post_type == 'programmation') {

    // get the action
    $wp_list_table = _get_list_table('WP_Posts_List_Table');  // depending on your resource type this could be WP_Users_List_Table, WP_Comments_List_Table, etc
    $action = $wp_list_table->current_action();

    /* $action return -1 if I don't choose my action from the bottom dropdown... */

    $allowed_actions = array("archive");
    if(!in_array($action, $allowed_actions)) return;

    // security check

    // make sure ids are submitted.  depending on the resource type, this may be 'media' or 'ids'
    if(isset($_REQUEST['post'])) {
        $post_ids = array_map('intval', $_REQUEST['post']);

    if(empty($post_ids)) return;

    // this is based on wp-admin/edit.php
    $sendback = remove_query_arg( array('archived', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
    if ( ! $sendback )
        $sendback = admin_url( "edit.php?post_type=$post_type" );

    $pagenum = $wp_list_table->get_pagenum();
    $sendback = add_query_arg( 'paged', $pagenum, $sendback );

    switch($action) {
        case 'archive':

            $archived = 0;
            foreach( $post_ids as $post_id ) {

                if ( !perform_archiving($post_id) )
                    wp_die( __('Error while archiving spectacle.') );

            $sendback = add_query_arg( array('archived' => $archived, 'ids' => join(',', $post_ids) ), $sendback );

        default: return;

    $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view'), $sendback );


Thank's for your help.

share|improve this question
Does anybody have an idea ? – Jonathan Lafleur May 21 '14 at 1:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.