How to empty wordpress custom post Database table

I used a custom page template to delete all the post from the wordpress database. Everytime I would go to this page it would delete 300 posts.The code for the page template is: <?php // Get 300 custom post types pages, set the number higher if is not slow. $mycustomposts = get_posts( array( ‘post_type’ => … Read more

$wpdb->delete column values IN ARRAY()?

No, wpdb::delete does not handle anything other than WHERE field = X. You can just use the query method instead: $ids = implode( ‘,’, array_map( ‘absint’, $ids ) ); $wpdb->query( “DELETE FROM table_name WHERE ID IN($ids)” );

How to move existing WordPress wp-content folder along with database to new server and new domain name?

There’s a pretty good step by step on moving WordPress in the Codex. It is what I follow when changing domains. Moving the files is pretty straight-forward. It is the hard-coded references in the database that are tricky. However, serialized search and replace will take care of all database changes. I’ve used the Velvet Blues … Read more

Slow wp_term_relationships query

Prepare yourself for an unsatisfying answer… After several days of testing, the conclusion that I’ve come to is that, put simply, this isn’t WordPress’ “fault”. I believe another related issue on the server was putting undue strain on the system. This was simply one of the slower queries, which, since the server was under strain, … Read more

Forcing nickname as display_name in custom edit profile template

I’m not 100% sure if I follow the logic of your question. But this is probably what you need: if ( !empty( $_POST[‘nickname’] ) ) { wp_update_user( array (‘ID’ => $current_user->id, ‘display_name’ => esc_attr( $_POST[‘nickname’] ) ) ) ; update_user_meta($current_user->id, ‘nickname’, esc_attr( $_POST[‘nickname’] ) ); update_user_meta($current_user->id, ‘display_name’, esc_attr( $_POST[‘nickname’] ) ); } Attention: update_usermeta has … Read more

find a random blogid across my multisite network that has at least one post published

An example that displays an admin notice listing a randomized array with all blog IDs, the result of a get_posts( array( ‘numberposts’ => 1 ) ) and marking the first one which get_posts result is different from zero. Result After refreshing: Code add_action( ‘admin_notices’, ‘wpse_60401_print_random_blog’ ); function wpse_60401_print_random_blog() { global $wpdb; $rows = $wpdb->get_results( $wpdb->prepare( … Read more