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


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

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


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!


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

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


2

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


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

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

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

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

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

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

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

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

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

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

By your reputation , It seems that you know about the wordpress very well. Use of prepare method in query is to make sure we're not dealing with an illegal operation or any illegal characters.So I recommend you to delete with the prepare method. Other than that, you might be aware of SQL INJECTION. Before release of wordpress 2.5, there was ...


1

Your query is wrong because your third argument to TIMESTAMPDIFF is incorrect. You should be using meta_value instead of SELECT meta_value. SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_wp_kc_last_active_time' AND TIMESTAMPDIFF( second, now(), TIMESTAMP(meta_value) ) > 5184000; Try that and see if the results start looking correct. I just ...


1

I did it this way. Opened Google analytics and Moved around 20 worthy posts manually to a new username, then delete all psots by admin, then moved worthy posts back. But f you have hundreds of worthy posts, then we need plugin.. someone need to create. But it should works like a counter first to gather views statistics..


1

WordPress automatically handles that if you force delete the page instead of thrashing it. The following function takes a parameter to force delete -> wp_delete_post( $postid, $force_delete )


1

First, you need a list of all available URIs. You may use my plugin T5 All URIs for that. Just activate and go to your blog on /alluris/. There is also a link to the file in your plugin list after activation. Then you need your log files, ideally one file with all requests from a long period (one year?). Run a grep for each line from all-uris over your ...



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