I am creating a plugin to display all posts from all custom post type. It is something like in edit.php, but instead of displaying single post type, I would like to display all posts in one page from multiple custom post type.

I follow the tutorial at here to create the plugin and I did it. However there is one problem now, I want to add the trash link under every listed posts (just like in edit.php). This field requires a nonce in order to run, but I couldn't get it how it works.

Here is my codes:

function column_post_title($item){
$actions = array(
        'edit' => sprintf('<a href="'.admin_url('post.php?post=%s&action=edit').'">Edit</a>',$item['ID']),//this part is fine
        'trash'=> sprintf('<a href="'.wp_nonce_url(admin_url().'post.php?post=%s&action=trash', 'trash-%s').'">Trash</a>',$item['ID'],$item['ID']),//here I cant get it right!!
return sprintf('%1$s %2$s', $item['post_title'], $this->row_actions($actions) );

Do I need to create own nonce? Or using the exist one (if there is any). From the code above it give me WordPress failure notice with:

Are you sure you want to do this? Please try again.

1 Answer 1


Just use get_delete_post_link( $post_ID ) - it'll return the absolute URL with nonce and all!

Just to be clear, this will get the link to trash posts (if trash supported). If you want to skip trash & get the perma-delete link, pass a second argument of true*.


Update: Having checked the source, it seems the codex is a little out of date. The second argument is deprecated, so pass an empty string & the third arg as true:

get_delete_post_link( $post_ID, '', true );
  • But I don't want delete, I just want to move the posts to trash.
    – dev-jim
    Aug 11, 2012 at 13:37
  • @tc.k - you've to echo the first code get_delete_post_link( $post_ID ) to only trash it. the second one will permanently delete that post
    – Amit Kosti
    Aug 11, 2012 at 13:56
  • Okay..i tested it...it works!!!thank you very much!!!
    – dev-jim
    Aug 11, 2012 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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