Showing posts with label commutecast. Show all posts
Showing posts with label commutecast. Show all posts

Wednesday, September 22, 2010

WordPress Shows Off Its Elegance

Some days it feels like WordPress, like any large software project, has just overgrown itself into a klugy mess. And then you have today. Where, once again, WordPress demonstrated just how elegantly their plugin API can be.

The challenge: update the home page show it never shows posts from one particular category. My first thought was to override the home.php template, throw away the Loop query that was there, and create a new one minus the category in question using query_posts.

Luckily, I found blogmum's article on the topic before I started in on that hacked mess of an idea. Here's how you solve the above problem elegantly:

function exclude_category($query) {
  if ( $query->is_home ) {
   $query->set('cat', '-xx');
  }
  return $query;
}

add_filter('pre_get_posts', 'exclude_category');

The magic behind this is the pre_get_posts filter that allows you to cleanly modify the query before it's run against the database.

Using filters like this is a wonderfully clean way to extend WordPress, and one I too frequently forget to employ.

Wednesday, March 26, 2008

Code Gotcha Of The Day

First time I've fallen for this one. I was sanitizing a production database for development use and ran the following query to reset everything:

  UPDATE users SET password = '123456' AND email = xxx@abc.com';

See the problem? Neither did I for a few seconds, and then realized that MySQL treated the above as:

 UPDATE users SET password = ('123456' AND email = xxx@abc.com');

So, I reset every users password to 0 and left e-mail alone.

What I really meant was:

  UPDATE users SET password = '123456', email = xxx@abc.com';

What a difference 3 characters can make.

Friday, January 26, 2007

Commutecast #2: Review of a CD and more practice

Here's my latest attempt at publishing a commutecast. I've still got a long way to go before I'm the next Bob Edwards or Ira Glass. Or even the next guy who brings coffee to those guys.


Gabcast! Ben's Commutecast #3 - Review of a book on CD and chatting

My review of How to Help Your Husband Make More Money So You Can Be a Stay-At-Home Mom by Joanne Watson and just chatting about my commute in general.

Gabcast! Ben's Commutecast #4 - Continue previous commutecast

See the commutecast right before this one. Had to pause to call Shira.

Thursday, December 28, 2006

Commutecast #1: Trying it out

Gabcast! Ben's Commutecast #1 - First Commutecast

This is my first ever commutecast. For now, it's just me blabbing, trying out gabcast.

Links mentioned in this commutecast:

  • Drive Time: A weekly video blog produced during my daily commute - link
  • Hidden Kitchens: Stories and More from NPR's The Kitchen Sisters - link
  • Gabcast - link