Hot answers tagged

14

I don't think there exist one, but you could create your own, wpse_empty_trash, with something like this: /** * Add a custom hook 'wpse_empty_trash' */ add_action( 'load-edit.php', function() { add_action( 'before_delete_post', function ( $post_id ) { if ( 'trash' === get_post_status( $post_id ) && ...


6

This is a much safer query to use and will remove related entries from the postmeta and term_relationship, unlike deathlocks query in his answer. Change the {id} to the id of each blog posts table. You can combine this query to run all the post tables at once, but try this on one table first. I've used it many times on single WP installs. DELETE a,b,c FROM ...


5

I use this to delete associated media with post. If you want to test against a certain post type you can include the global $post_type variable. Pretty much it gets all attachments and deletes them one by one. Reference function delete_associated_media( $id ) { $media = get_children( array( 'post_parent' => $id, 'post_type' => '...


4

Is it safe to directly delete all rows in the wp_posts table that have a post_type of revision? (I've seen conflicting answers on this—but I'd love to be able to just do it this way if it's safe) Safe, it's safe. If there is only one user (you) that can edit posts on site it's safe and does not bring any other problem. If there are more, and one is ...


3

If you mean the delete button on the user list at /wp-admin/users.php, then that button is created by the WP_Users_List_Table class around (currently) line 256. If you look a little further down-- a few lines-- you will see a filter called user_row_actions. You can use that to hide the 'delete' link. add_filter( 'user_row_actions', function($actions, $...


3

To redirect after the use of get_delete_post_link() it's probably easiest to hook into the trashed_post action: Code: add_action( 'trashed_post', 'wpse132196_redirect_after_trashing', 10 ); function wpse132196_redirect_after_trashing() { wp_redirect( home_url('/your-custom-slug') ); exit; } Or you could make it dependent on the according $_GET ...


3

Nonce You are going to want to set a nonce hidden field or to the element so that you can verify the request. Take a look at the codex for examples. Setting the POST ID and Nonce You will need to add the id of the specific post to the delete button or to a hidden input field associated with that entry. I have the example setup so you will need to add ...


3

You can set a time interval for automatically empty trash: In your wp-config.php put: define('EMPTY_TRASH_DAYS', 1 ); //Integer is the amount of days EDIT: To disable trash set the number of days to zero (http://codex.wordpress.org/Editing_wp-config.php) Hope it helps!


3

Deleting the attachment post columns will potentially affect WordPress recognising that the images exist - they'll still be stored in your /uploads/ directory, but may be unavailable for use within core WordPress functions.


3

WordPress categorizes every upload as an attachment post-type which is built into your install by default in a similar manner as Pages, Posts, or Comments. If you delete row upon rows of attachment post types in your database you will lose availability to these in the Media Module ( Add Media button ) and won't be able to edit the information ( title, alt, ...


2

ended up using ajax in the end... html; <a class="remImage" name="<?php echo $attachment->ID; ?>" href="#"><?php _e('delete');?></a> <input type="hidden" id="att_remove" name="att_remove[]" value="<?php echo $attachment->ID; ?>" /> <input type="hidden" name="nonce" id="nonce" value="<?php echo ...


2

The relationship between the term and the post is deleted, not the term itself. On front-end the query for a term with no associated posts will result in a 404 tough. But if you go to the term list in back-end you still can see term with a post count of 0. Always keep in mind that the Codex is a community project: Everybody can improve it, everybody can ...


2

The revisional feature of WordPress is only for users. That means, that if you don't need them old revisions, you can safely delete them. The system actually doesn't care.


2

As i'm new to wordpress.stackexchange.com, i cannot comment (silly idea) To further extend Chip's answer. You can also delete all revisions from the database which appear before X date to remove old revisions that are not needed, whilst keeping newer revisions to what ever limit you want. simply run the query: DELETE FROM `wp_posts` WHERE `post_type` = '...


2

You'll need to edit wp-config.php. To set posts to retain a set number of revisions: define('WP_POST_REVISIONS', 3); To disable post revisions completely: define('WP_POST_REVISIONS', false );


2

This may be what you're looking for http://wordpress.org/extend/plugins/suicide/. As a super admin you can select which sites you would like to remove the content from within your multisite setup.


2

Terms should work like categories (which basically they are but with with different names). They are attached to posts but not dependent upon them. If you delete a post the term stays, like with categories. Custom post meta is dependent upon its post and will be deleted when the post is permanently deleted. It isn't deleted when the post is 'trashed'.


2

There is also a plugin, WP Optimize that can help you do this From the website: WP-Optimize is a WordPress 2.9++ database cleanup and optimization tool. It doesn't require PhpMyAdmin to optimize your database tables. It allows you to remove post revisions, comments in the spam queue, un-approved comments within few clicks.


2

You could also do this, function mod_redirect_subscriber_delete($user_id) { $user = get_user_by('id', $user_id); $role = $user->roles[0]; if ($role == 'subscriber') { add_action("deleted_user", function(){ wp_redirect( admin_url('/index.php') ); exit; }); } } add_action("delete_user", "mod_redirect_subscriber_delete"); ...


2

If you need to retain only images for last 50 posts, I don't think that a cron job or a WP cron is the best thing you can do, in WordPress you can know when a post is published, and you can run a routine everytime it happen, deleting images for the post pubblished 50 posts ago. That's easy, better performing (you do nothing if you have nothing to do, a cron ...


2

@s_ha_dum suggests that Post meta will be deleted automatically. Therefore because his reputation suggests he knows what he is talking about, this solution only handles Post attachments. I'd suggest checking out the docs for the before_delete_post() hook, as it's quite handy to be able to check out what Post Type is being deleted, etc. add_action('...


2

Considering this site is WordPress Development, I'm assuming you would like to know how to (force) delete posts programmatically. wp_delete_post(257, true); // `true` indicated you would like to force delete (skip trash) More on wp_delete_post() function


2

I would use the Search Regex plugin. It will allow you to use a regular expression to find and replace (in your case delete) inline styles. Make sure you backup your database before you begin! A simple regular expression that should work for you would be (style=").*" It will look for a string starting with style=" and containing any number of ...


2

Just for clarity: borrowing from this answer, add the following to your theme's functions.php: function wpse_188427_delete_post_media( $post_id ) { $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'any', 'post_parent' => $...


2

Taxonomy "data" is indeed stored in the database. Taxonomy "definitions" are not. The stuff you put into a call to register_taxonomy is not the data, it's the definition of that data. Stuff you add, like categories or tags, is the data, and yes, it goes in the taxonomy tables like any other taxonomy data. You need to call register_taxonomy every time so ...


1

Rather than "still on" page the user actually goes to the link and then sent back after post is deleted. From your description and quick look at code this is probably line that sends user back: wp_redirect( add_query_arg('deleted', 1, $sendback) ); Since destination is filtered inside wp_redirect() $location = apply_filters( 'wp_redirect', $location, $...


1

Ok s_ha_dum, I got it to work with some changes: the "count" seems to ruin the function but like this, it worked like a charm: function test($actions, $user_object) { if ( 'subscriber' !== $user_object->roles[0]) {unset($actions['delete']);} return $actions; } add_filter('user_row_actions','test',1,2); Thank you for you great help!


1

If you will delete the custom posts, if you kill a user, then hook inside the delete_user Hook. This hook give you the possibility to call actions and doing other jobs, like delete posts to this user id. See the codex for more information and a example source.


1

'Every night' sounds like it's triggered via a cronjob. You may install the wp-crontrol plugin to see what cronjobs are sheduled in your wordpress install. If you don't see something obvious there I would also suppose it happens outside of wp. But as you already pointed out, you can only be sure when you revert everything to a stock install (disable plugins ...


1

Run SQL query: DELETE FROM wp_posts WHERE post_type = "revision" // for "wptest" DB, note the table name NOTE: The above query “just deletes post marked as revisions. If for some reason you associated a revision with a tag or a category that was then removed when the final post was published, you will have extra entries in other tables such as terms.” The ...



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