Never-Ending Pagination in WordPress

Take your site’s slideshows to the next level with the following: [code language=”php”]// Slightly different way of getting a previous post than get_adjacent_post(), this // function will grab a post in a SINGLE specific category. We’ll go ahead and // return it as a permalink since that’s ultimately what we want anyways. function rdc_get_prev_url_in_category( $in_categoryContinue reading “Never-Ending Pagination in WordPress”

WP-Config Options You Probably Didn’t Know About

1. Override options “siteurl” and “home” [code language=”php”]define(‘WP_SITEURL’, ‘http://your-sites-address.com’); define(‘WP_HOME’, ‘http://your-sites-address.com’);[/code] 2. Revisions [code language=”php”]define(‘WP_POST_REVISIONS’, FALSE); define(‘WP_POST_REVISION’, 3);[/code] 3. AutoSave Interval [code language=”php”]define(‘AUTOSAVE_INTERVAL’, 160);[/code] 4. New wp-content location [code language=”php”]define( ‘WP_CONTENT_DIR’, $_SERVER[‘DOCUMENT_ROOT’] . ‘/somewhere/wp-content’ ); define( ‘WP_CONTENT_URL’, ‘http://server.com/somewhere/wp-content’); define( ‘WP_PLUGIN_DIR’, $_SERVER[‘DOCUMENT_ROOT’] . ‘/somewhere/wp-content/plugins’ ); define( ‘WP_PLUGIN_URL’, ‘http://server.com/somewhere/wp-content/plugins’);[/code] 5. Manage cookie options [code language=”php”]define(‘COOKIE_DOMAIN’, ‘www.server.com’); define(‘COOKIEPATH’,Continue reading “WP-Config Options You Probably Didn’t Know About”

Delete All Tags With 0 Posts

Delete all tags with zero posts tagged. Can also be used to delete all tags with one post. Or other amounts … Use at your own risk. From the MySQL command line. Make sure to BACK UP YOUR DATABASE first. [code language=”sql”] DELETE a,c FROM dbname.wp_terms AS a LEFT JOIN dbname.wp_term_taxonomy AS c ON a.term_idContinue reading “Delete All Tags With 0 Posts”

SQL_CALC_FOUND_ROWS and no_found_rows

By default, the WordPress SQL query that selects posts from the database will use “SELECT SQL_CALC_FOUND_ROWS …”. This is mainly for pagination purposes, to speed up subsequent queries for the next set of results. Writing the query that way certainly helps speed up the site as a whole, but is useless in some circumstances. Remedy:Continue reading “SQL_CALC_FOUND_ROWS and no_found_rows”

Merry Christmas, Now Patch Your WordPress Sites!

Thanks to the release of http://seclists.org/fulldisclosure/2012/Dec/242 on Christmas Eve, I’ve spent my holiday working security for several sites. This exploit allows an attacker to take advantage of the “open” nature of W3 Total Cache’s cache files to extract password hashes from the database cache. I agree with JasonĀ on this – why did the author ofContinue reading “Merry Christmas, Now Patch Your WordPress Sites!”

Rewrite WP Attachment Images on the Fly

At first, this may not seem to have any real-world use, but consider this: You need to set up an independent development environment for your site, and you’d rather not copy gigabytes of files from your production server’s wp-content directory. Without the following function, keeping everything synced could turn into another full-time job, especially ifContinue reading “Rewrite WP Attachment Images on the Fly”

Purge All WordPress Users of a Particular Role

I needed to delete all of the subscriber level users on one of my sites recently, and couldn’t find an easy way to do it. My solution? Write some code. It was definitely quicker and easier to run this snippet than to manually delete over 7,700 users from my database. Drop this code into anContinue reading “Purge All WordPress Users of a Particular Role”