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.
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
http://codex.wordpress.org/Function_Reference/get_delete_post_link
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
: