We’re rewarding the question askers & reputations are being recalculated! Read more.

Hot answers tagged

9

You can use wp_delete_post. To get all posts with the "trash" status: $trash = get_posts('post_status=trash&numberposts=-1'); Then: foreach($trash as $post) wp_delete_post($post->ID, $bypass_trash = true);


5

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 ...


5

There are multiple actions. Listed in order of appearance with their parameters: untrash_post - (int) $post_id // before restoring transition_post_status - (string) $new_status, 'trash', (object) $post trash_to_{$new_status} - (object) $post // useful to address a special trash to status action untrash_post_comments - (int) $post_id // before associated ...


4

From your comment above, I believe you're running into issues with the _wpnonce piece of the puzzle. Looking at the code in /wp-admin/post.php, it appears that the untrash instruction is checking for a valid WordPress nonce, and not getting one. This might do the trick: <?php function wpse_95348_undelete_post( $post_id ) { // no post? if( !$...


4

Hook into load-{screen_id} and check if the $_GET['trashed'] variable is 1 or above. add_action('load-edit.php','wpse_trashed_redirect'); function wpse_trashed_redirect(){ $screen = get_current_screen(); if('edit-page' == $screen->id){ if( isset($_GET['trashed']) && intval($_GET['trashed']) >0){ $redirect = ...


4

There is not wp_undelete_post but you have other choices: wp_untrash_post(): when post is trashed, the previous status is stored in _wp_trash_meta_status meta field. wp_untrash_post() restore trashed posts to previous status whatever it was; for example, private, inherit, publish. I've not tested it but it should work with a custom post status as well. ...


4

When post is trashed, WP creates a meta field named _wp_trash_meta_time and it saves trashed time in that field. You can use that field to get trash time. Edit: Example: $args = array( 'post_status' => 'trash', 'post_type' => 'post', 'nopaging' => TRUE, 'meta_query' => array( array( 'key' => '...


4

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 ...


4

Try these: /** * Removes the "Trash" link on the individual post's "actions" row on the posts * edit page. */ add_filter( 'post_row_actions', 'remove_row_actions_post', 10, 2 ); function remove_row_actions_post( $actions, $post ) { if( $post->post_type === 'prj' ) { unset( $actions['clone'] ); unset( $actions['trash'] ); } ...


4

Short answer Yes, it does ;) Long answer The function that is used to empty the trash/remove trashed posts is called wp_scheduled_delete. When you'll take a look at it's code, you'll see, that it uses wp_delete_post to delete the posts and inside wp_delete_post the action delete_post is run as you can see here.


3

Hook onto trashed_post and use wp_untrash_post() to reverse upon meeting a condition, pseudocode example... add_action('trashed_post', 'wpse_218031_trashed_post'); function wpse_218031_trashed_post($post_id){ //use post_id to check conditions... if not met call: if ( $some_condition ) { wp_untrash_post($post_id); } } trashed_post runs ...


3

Unless there's a very good (usually performance, or, of course, inability of core functions to do what you need) reason to use raw SQL requests to fetch posts and other data in WordPress, you shouldn't construct your own SQL queries. Instead, you can use WP_Query. In your case, you could fetch the posts like this: $query = new WP_Query( array( '...


3

Ok, I think I've figured out a viable solution. Kinda disappointed that there's no way I've found thus far to hook directly into trash_{custom_post_type} like I was able to on the publish_{custom_post_type} hook. Here's a solution for anyone else struggling with this issue. If anyone has any better suggestions, please feel free to share! /** * ...


3

Well, this is partly true and partly false. When you trash a post, everything that is tied to it is also trashed. This means, if you untrash the post, the comments etc. are untrashed as well. However, comments and other stuff is not handled as if they were trashed directly (i.e., on the Comments page in your WordPress Admin). If you directly trash a ...


3

Use wp_trash_post instead, and keep in mind {post_status}_{post_type} so originally it should have been trash_empresa not trash_post, try wp_trash_empresa too


3

Just as @cybmeta mentioned, the info is stored in the post meta table. When we trash a post then the post meta key _wp_trash_meta_status is added with the value of the previous post status (publish, pending, draft, ... ). Within the wp_trash_post() function, we have: add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']); add_post_meta($...


3

The only way to restore it is to restore a backup of your MySql database. Login to your web host and see if there are any backups of your database available. Then you can restore the backup and it will bring that content back. Make sure you haven't added any other content after the backup timestamp or else you will lose that. If you want to make a manual ...


3

From looking at the source quite curiously $force_delete argument in wp_delete_post() only applies to native posts, pages, and attachments. My quick guess would be that for CPTs you would need to use explicit wp_trash_post() function if you want trash behavior.


3

That's not how get_post() works. Trashing the post doesn't change the value of the theme mod, and the theme mod is still going to point to that post in the database, so get_post() will dutifully retrieve it as long as it's there. It's up to you to make sure its status is what you want before display: $featured_post = get_post( get_theme_mod( '...


2

This is done filtering the *_row_actions. For the Comments screen (/wp-admin/edit-comments.php) this is the hook: add_filter( 'comment_row_actions', 'comments_row_wpse_92313', 15, 2 ); function comments_row_wpse_92313( $actions, $comment ) { if( !current_user_can( 'delete_plugins' ) ) unset( $actions['quickedit'], $actions['edit'], $actions['...


2

When deleting a user, WordPress displays a warning that unless you attribute the user's posts to a new user, it's posts will be deleted and you cannot undo those deletions. That means the only way to restore the posts and media is to restore a backup of the WordPress instance or database which you hopefully have.


2

With the filter we prevent the Trash link from being printed. And with the action, redirect back to the post listing page if the user tries to access the URL directly (/wp-admin/edit.php?post_status=trash&post_type=post). add_filter( 'views_edit-post', 'wpse_74488_remove_trash_link' ); add_action( 'admin_head-edit.php', 'wpse_74488_block_trash_access' );...


2

Try to specify the following capability, it helped in my case: ,'delete_published_posts' => 'delete_published_mro_project'


2

This would be quite challenging to implement. Posts can be trashed because: They have a concept of status and corresponding field in database table WordPress code "knows" to only deal with posts of appropriate status for most purposes This solves issues of visibility (posts won't appear on front end) and interaction (trashed posts won't show up as ...


2

You can hide move to trash button via adding css in the admin area. Try following code in functions.php file: function my_custom_admin_styles() { ?> <style type="text/css"> .post-type-inhoud form #delete-action{ display:none; } </style> <?php } add_action('admin_head', 'my_custom_admin_styles');


2

Tested out the code that was provided by user3888958, but didn't work for me. here's my own version which hide the Move to Trash link: add_action( 'admin_head', 'wpse_237305_disable_trash' ); function wpse_237305_disable_trash() { global $pagenow; if ( $pagenow == 'post.php' ) { ?> <script type="text/javascript"> ...


2

You can check the value of the post_status query variable and make sure that it's set to trash: function wpse239286_trash_column( $columns ) { // Bail if we're not looking at trash. $status = get_query_var( 'post_status' ); if ( 'trash' !== $status ) { return $columns; } return array_merge( $columns, array( '...


2

save_post gets fired, once the post is saved. We get the current post object as the second parameter. So we can check, if the current post status is trash: <?php add_action( 'save_post', function( $post_ID, $post, $update ) { if ( 'trash' === $post->post_status ) { return; } /** do your stuff **/ }, 10, 3 ); ?>


2

If you don't have any posts in the Trash, then there won't be a link to go and see them. What would be the point of displaying a link to an empty page, after all? The link to Trashed posts appears on the All Posts screen at the top, right alongside All | Published | Drafts and so forth. If you want to see it appear, make a new post, and then trash that post ...


2

I would discourage using raw SQL for moving a post to a trash or back, especially since there's a build in function for it: wp_trash_post( $post_id ); More about the wp_trash_post() function. The opposite is: wp_untrash_post( $post_id ); wp_untrash_post() also untrashes trashed comments. In WP there are functions for many things - for instance you ...


Only top voted, non community-wiki answers of a minimum length are eligible