I took a peek at the code in edit.php and am now generating links with this code:

wp_nonce_url("/wp-admin/edit.php?doaction=trash&post_type=post&ids=postIds", "bulk-posts")

The string "postIds" in the URL gets replaced by comma-separated post IDs via javascript. All this does thus far is redirect me to the edit screen in the backend. How do I need to generate this link to trash multiple posts at once?


It should be action instead of "doaction", then it will work just fine.

As for your request for some documentation, as far as I know there is no overview about parameters/actions available at edit.php. So lets do some source code inspection, as you said yourself, you have gotten the inpiration for your approach from the edit.php, so we start there.
You have gotten mixed up because of the variable $doaction, which does get set up like this:

$doaction = $wp_list_table->current_action();

Now we need to know how $wp_list_table is initialized:

$wp_list_table = _get_list_table('WP_Posts_List_Table');

So by using _get_list_table(), which does

Fetch an instance of a WP_List_Table class.

In this case, as seen from the call, WP_Posts_List_Table.

As seen above the method current_action() gets called to determine the action. This does actually rely on the parent class

return parent::current_action();

which is the class WP_List_Table, where the action gets set up by current_action() like this:

 * Get the current action selected from the bulk actions dropdown.
 * @since 3.1.0
 * @access public
 * @return string|false The action name or False if no action was selected
public function current_action() {
    if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) )
        return false;
    if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
        return $_REQUEST['action'];
    if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
        return $_REQUEST['action2'];
    return false;

Recognized - at the edit.php that is - values for the parameter action are:

  • trash
  • untrash
  • edit
  • delete and delete_all

as it can be seen at the switch statement for $doaction and beforehand the extra condition for delete_all.

| improve this answer | |
  • Don't mention it, you're welcome. Ah, ok, I see it now :) I'm cleaning up the comments, you can do the same, if you want to @Florian – Nicolai Jul 21 '15 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.