I am running a Buddypress Website with 8k Users and I want to create a fresh installation as a base for a new project. I do not want to touch the DB directly because I feel it's dirty and could potentially create conflicts - hence I wanted to clean all users except the administrators just once. Running wp_delete_user takes ages on a managed cloud server - basically my scripts are timing out after 5minutes with just 300 users deleted. Is …
I want to delete the post attachments too from the 'Media" panel once a custom post is deleted. The post itself gets deleted well, but its media still remains in the wordpress "media" panel: Archive page: <?php if (isset($_POST['delete-btn'])) { $deletePost = $_POST['post-id']; wp_delete_post( $deletePost, true); do_action( 'delete_post', $_POST['post-id'] ); } ?> Functions.php: //delete all media attached with deleted post add_action( 'delete_post', 'delete_post_children' ); function delete_post_children( $post_id ) { wp_delete_attachment( $post_id ); }; //delete all media attached with deleted post …
I want to remove a post from PHP by title. I have a code for publish or update if the post exist by title, but I don't know how to insert the wp_delete_post() function. This is my actual code for publish or update if the post exist by title: <?php // require wp-load.php to use built-in WordPress functions require_once("/var/www/mysite.com/wp-load.php"); //Title $TítleProduct = ("Title Product 1"); //Desc $Desc = ("Product descripction 1"); // Register Post Data $post = array(); $post['post_status'] = …
I created a new custom post type that users can add new post from frontend and it works as desired. Now, I´m trying to add a button to delete. This is the code triggered by the button: if( has_post_thumbnail( $post_id ) ) { $main_image_id = get_post_thumbnail_id( $post_id ); wp_delete_attachment( $main_image_id , true ); } if( get_post_meta( $post_id , 'token_personagem' , true ) ) { $token_id = get_post_meta( $post_id , 'token_personagem' , true ); wp_delete_attachment( $token_id , true ); } wp_delete_post( …
I want to update the confirmation form for delete user. If user has posts, it shows Attribute all content to - option to reassign other author for his posts. It takes lots-of time to load the page, if there are thousands of users in the system. (we have 55k+ users) So, I want to change the User option (Attribute all content to) from Drop-down to Type and Search. I've tried to found the hooks/action but could not found that I …
I am trying to delete a lot of WordPress posts programmatically using wp_delete_post, but not all posts are deleted successfully. In some cases I get NULL as a return value for wp_delete_post($row->post_id, true) and the post isn't deleted from the database. There are both post and page post_types amongst those not deleted posts, as well as custom post types. What can be the issue there, why aren't some posts deleted, while many others are deleted successfully?
Hello please does anyone know a way to automatically delete posts that doesn't get views within a period of time. Lets say if a post on my site is made and within 30 days, there are no views on the post, is it possible to automatically place the post in draft or delete it
I have a function (see in full below) that syncs data into WP from an external database. It's a list of scheduled items. When the schedule is updated, old data should be deleted. See this snippet: $wpdb->delete( $table, array( 'schedule_item_id' => $item->id ) ) But this is not happening. For example if I have an item "A" scheduled on a Tuesday at 6pm, then I remove that from the external database and I replace it with ietm "B" scheduled at …
I am trying to update the value of one custom post type's meta when another custom post type is deleted. When a space_rental is deleted, I need to update some meta value on a space. I don't think I can use delete_post because it fires after the meta data has been deleted, but this isn't working for me either (either on trashing the post or emptying the trash). Here is the function and below that is the structure of the …
I've 2 almost identical posts: https://webscraping.pro/reliable-open-proxies-for-business-directories-scrape/ https://webscraping.pro/reliable-rotating-proxies-for-business-directories-scrape/ I want to delete first one to remove excess... Since I might have left permalinks to it (first one) at other blogs or social services, so I want to keep its slug that is /reliable-open-proxies-for-business-directories-scrape/ and make that slug to refer to the second post. This way visitors gets redirected to the second post when hitting the slug of a deleted post.
I have a custom post type, that can be editable by more than one user. Each post of that type has a field with the user ids who can edit it (kinda like co-authors). But since many users have permissions to the post, I am not sure how to prevent deletion by other users (not in the co-authors' list). Right now the problem is only present in the REST API which is used to delete from the frontend. Is there …
I have created a form where users update their profile. When a profile is created or updated it creates a CPT called course. The url is the permalink + /course/ + the title of the course /* CREATING COURSE PAGES FROM USER PROFILES */ function create_course_page( $user_id = '' ) { $user = new WP_User($user_id); if ( ! $user->ID ) return ''; // check if the user whose profile is updating has already a post global $wpdb; $course_post_exists = $wpdb->get_var( …
I've got only one function left that I need to solve (if it's solvable). I've got a frontend post system for unregistered users. But there are no way for the users to delete a post if they later want. So I was thinking, if I in my form (where they create their post), ask them to write a password in a custom field, is there then anyway to delete the post by using the post id nr and the password …
I'm having a problem with an unwanted page not disappearing, and continuing to be referenced even when replaced with another page. Here's the situation. I have 2 pages with different versions of the same content. Call them page_old and page_new. I want to get rid of page_old first. After that's done, I want to rename page_new to page_old. I'm trying the following, in this order: 1. In Appearance > Menus, remove the menu item for page_old. 2. In my All …
I have a code block to delete all the products from a store. This products have several custom fields and some images attached. The code is below: set_time_limit(0); define('WP_USE_THEMES', false); require_once("../../wp-load.php"); $query = new WP_Query(array( 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'post_type' => array( 'product' ), 'post_status' => array( 'publish' ), 'posts_per_page' => -1, 'fields' => 'ids' )); foreach ($query->posts as $ID) { $media = get_attached_media('', $ID); foreach ($media as $image) { wp_delete_attachment($image->ID, true); } wp_delete_post($ID, true); } The problem …