So just thought I would update with the solution I came up with incase anyone run across this in the future.
What I did was rebuild the url in the function and pass the ids in the url to the template page.
function custom_bulk_action() {
global $typenow;
$post_type = $typenow;
if($post_type == 'post_type') {
// 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();
$allowed_actions = array("export");
if(!in_array($action, $allowed_actions)) return;
// security check
check_admin_referer('bulk-posts');
// 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 = get_site_url() . '/whatever/?';
switch($action) {
case 'export':
// if we set up user permissions/capabilities, the code might look like:
//if ( !current_user_can($post_type_object->cap->export_post, $post_id) )
// wp_die( __('You are not allowed to export this post.') );
$exported = 0;
foreach( $post_ids as $post_id ) {
if ( !$this->perform_export($post_id) )
wp_die( __('Error printeting post.') );
$exported++;
}
$sendback = add_query_arg( array('ids' => join(',', $post_ids) ), $sendback );
break;
default: return;
}
$sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback );
wp_redirect($sendback);
exit();
}
}
Once I got the ids in the url I put them into an array $postIds = explode(',', $_GET['ids']);
and called them in the WP_Query
args using post__in
.
There’s probably a bit of unnecessary code left in there but it gets the job done.