How to bulk delete posts in WordPress with MySQL

Every once in a while, we need to spend time pruning our WordPress databases. But if part of your pruning task includes deleting a metric ton of posts, this can become time-consuming if you’re using the WordPress Dashboard to do it. Fortunately, there’s a quicker way to delete those hundreds, or even thousands, of posts without checking a bunch of boxes and clicking a button a couple of hundred times.

Enter MYSQL

WP-Guru has a great tutorial, complete with screenshots and example code, that will walk you step-by-step through creating the queries you need to delete those posts. I’ve used this tutorial myself, and it has saved me loads of time. So head on over and take a look, and if you’re in need try it out.

How To Better Detect Your Mobile Visitors with WordPress’s WP_is_mobile Function

Although WordPress themes typically use Responsive Web Design to tailor websites for mobile devices, sometimes you may need to use PHP (the language WordPress is written in) to detect whether your visitor’s web browser is running on a mobile device. For example, you may want to output certain HTML markup (such as a mobile navigation menu) on mobile devices. Alternatively, you may only want to output a slider containing large images on desktop and not mobile devices. Doing this via PHP (instead of CSS) means that your visitor’s mobile browser won’t have to download all of the slider images even though the slider is never displayed, which also means that your site will load faster for your mobile visitors.

wp_is_mobile() is a function built into WordPress that detects whether the visitor is using a mobile device such as iPhone, iPad, Android, Silk, Kindle, BlackBerry, Opera Mini, and Opera Mobi. This is a conditional function, which means it returns one of two results: true or false. It’s located in wp-includes/vars.php.

The function was introduced in WordPress 3.4, and it can be used in a WordPress plugin or theme.

Here’s a simple example:

<?php
if ( wp_is_mobile() ) { // Visitor is on a mobile device} else { // Visitor is on a desktop (not mobile) device}
?>

WordPress core currently uses this function in a few different places:

  • To completely disable the Visual Editor for Opera Mini.
  • To enable jQuery UI Touch Punch in the WordPress dashboard for mobile devices.
  • To detect whether the current device can upload files.
  • To disable the “shake” effect on the WordPress login page when an incorrect username or password is entered using a mobile device.

You can also use this function to hold mobile-specific content, such as the navigation menu mentioned above. <?php if ( wp_is_mobile() ) {
/* Display and echo mobile specific stuff here */
} ?>

How Tony Perez of Sucuri Sets Up His Own Security

there have been a lot of posts about various wordPress security issues over the last couple of weeks, some of them giving good security advice and a lot of others giving not so hot advice. Here’s a post by Tony Perez (who is probably the greatest master of WordPress security) where he talks about what he does when setting up his own wordPress sites. I’m not affiliated with Tony at all, but I’ve heard him talk a couple of times, and he’s extremely knowledgeable when it comes to security. Tony links to a lot of other good posts, so be sure to read those as well.

Wordsesh Starts Tomorrow: Will You Be there?

Tomorrow marks a first in the WordPress community. there are WordCamps and meetups for WordPress all over the world, and at various times of the year. But tomorrow, (or Saturday according to UTC), we’re going to see what I hope will become a continuing trend: A virtual WordCamp called wordSesh. It’s being sponsored by WooThemes, and will be twenty-four hours of completely awesome WordPress content. The schedule of speakers is at the official WordSesh site, and you’ll be able to stream the content from there as well. Recordings of all the sessions will be available as well after the conference is over. I’d like to see if I could attend for the whole twenty-four hours, but I doubt that will happen, no matter how cool it would be. But I’ll definitely be listening to everything and blogging on it as well.

So the only question left is will you be there? I know there are a lot of bloggers using WordPress, and there will be content for everyone from end users to developers. I highly recommend attending. Hope to see you this weekend.