Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 require wpnonce 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. Message.

Thanks

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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:

get_delete_post_link( $post_ID, '', true );
share|improve this answer
    
But I don't want delete, I just want to move the posts to trash. –  dev-jim Aug 11 '12 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 Aug 11 '12 at 13:56
    
Oh yes...missed it...thanks –  dev-jim Aug 11 '12 at 14:02
    
Okay..i tested it...it works!!!thank you very much!!! –  dev-jim Aug 11 '12 at 14:04
    
+1 simple! thanks ;) –  dino May 29 '13 at 14:44

Your Answer

 
discard

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

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