How can I specify the post status of an untrashed post?

I think for your purpose wp_untrash_post_status filter will be enough. Will work with single and multiple posts restore. Filters the status that a post gets assigned when it is restored from the trash (untrashed). add_filter( ‘wp_untrash_post_status’, ‘change_untrash_post_status’); function change_untrash_post_status($status){ return ‘pending’; } P.S. apply_filtershook is used to call callback functions created by us, like a … Read more

How to restore all items from trash

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 … Read more

Trash in WP 3.8?

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 | … Read more

SQL Command for restoring trashed comments

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 … Read more

Remove Featured Image & All Media Uploaded to the Post

You can try using the function get_attached_media() like this: add_action( ‘before_delete_post’, ‘wps_remove_attachment_with_post’, 10 ); function wps_remove_attachment_with_post( $post_id ) { /** @var WP_Post[] $images */ $images = get_attached_media( ‘image’, $post_id ); foreach ( $images as $image ) { wp_delete_attachment( $image->ID, true ); } } Note that this will permanently delete all the image files related to … Read more

Get rid of “trash can” for custom post type

If you wanted to do this for all post types, you’d simply do define(‘EMPTY_TRASH_DAYS’, 0); see https://codex.wordpress.org/Trash_status#EMPTY_TRASH_DAYS_option. But since you only want to do this for a custom post type, you will need to hook into ‘trashed_post’ like this: add_action(‘trashed_post’, function( $post_id ){ […] then check your trashed posts’ post type: if ( get_post_type($post_id) === … Read more

How to retrieve the date on which a post was moved to trash?

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’ => ‘_wp_trash_meta_time’, ‘value’ => array( strtotime(“last week”), date(‘U’) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)