Tag: WordPress

Using meta_query With WordPress 3.1+

With WordPress 3.1 – we now have the ability to use “meta_query” to show posts associated with a certain custom field. I recently used this in order to create an events listing widget for a client. I needed to query posts in the “Events” category and that had a time stamp defined (which happened to be the start date of the event). The client wanted to show only current/future events (today or later) and wanted to show them in order by the closest event date to the furthest away.

Getting the general query together was a snap – but the orderby did not work unless I had the meta_key defined (this is documented but was overlooked initially).


$now = time();
$args = array(
	'category_name' => 'Events',
	'meta_query' => array(
			'key' => 'sdac_event_time_stamp',
			'value' => $now,
			'compare' => '>=',
			'type' => 'NUMERIC'
	'meta_key' => 'sdac_event_time_stamp',
	'order' => 'ASC',
	'orderby' => 'meta_value_num'
$events_query = new WP_Query( $args); 

If you take a look at the query itself – the trick was to capture the time now ($now) and then use the compare within the meta_query. Overall – this sort of query makes working with custom fields a lot easier. If you have not checked it out yet – take a look.

Function Reference/WP Query

WordPress Taxonomy Query (Keep it Simple)

Now that a number of people are using more and more custom taxonomies for WordPress – custom taxonomy queries are something becoming necessary.

Example: You have a WordPress site set up to show/sell products (in this example – you sell books and posters). You have a custom taxonomy called “catalog” that you use to organize all the products.

If you want to show all items that are marked “posters” in your custom catalog taxonomy you can simply use this query:

query_posts( array( 'catalog' => 'posters' ) ); 

Of course – you can create more complicated custom taxonomy queries, but this will get you started. By using custom taxonomies (and custom post types) – you can really open the door to creating complex content management systems (and/or really cool sites that need something more than your standard categories/tags/posts/pages).

Further documentation: http://codex.wordpress.org/Function_Reference/query_posts

Remember – keep it simple!

Custom Post Types Open the Door…

For the last five projects we have been working on – we have used Custom Post Types for all of them. While we first thought these were pretty cool to work with – we have since realized that these are amazing. We have implemented user submitted media, events, profiles, vendors, contributors, etc all using Custom Post Types. Since we would like to share the love…we are looking to make some really awesome plugins for the community. Anyone have something they think would be really cool and that would help a lot of people?

More Fun with WordPress Screen Options

Unlock the power of screen options
After taking a look at “Screen Options” on the WordPress menus page (Appearance > Menus) – I decided to spend some time going through the different “Screen Options” on each admin page view and would highly recommend you doing the same. This very useful tab allows you to:

  • Choose what you see on the dashboard (and how it is displayed)
  • Show/hide fields on the edit post page
  • Choose the number of posts/pages/categories/tags/plugins/users you see in those listings (great if you want to show more than the default number)
  • Show/hide columns in the posts/pages/categories/tags/plugins/users listings
  • Enable/disable accessibility mode (Appearance > Widgets)
  • Show/hide different options in WordPress menus (like mentioned in the previous post)

If you plan to spend a lot of time in the backend of WordPress – do yourself a favor and get familiar with these options as you will at some point find something useful about those options.

Include or Exclude Category for RSS Feed or Search

There are certain times when you need to include or exclude certain categories in the feed or search results. The easiest way to take care of this is to add the following to your functions.php file.

function sdac_remove_from_feed( $query ) {
	if ( $query->is_feed ) {
		$query->set( 'cat',-1 );
        return $query;
add_filter( 'pre_get_posts','sdac_remove_from_feed' );

The code above will exclude all posts that are in the category with ID 1 from your feed. If you wanted to exclude everything from the search results – you would change one line:
$query->is_feed to $query->is_search

If you wanted to only show items from the category with ID 1 – you would just need to remove the “-” before the category number.

Note: You can include/exclude items tagged, etc by changing the ‘cat’ to whatever else you would normally use in the query.

Neat and Useful wp-config Settings

There are a ton of great options available for you to put into your wp-config.php file which can help your site run smoother, give you that extra customization you wanted without the use of plugins, and aid in development and debugging.

Here are some highlights that can help save you time and headaches by adding the following to your wp-config.php file:

Help for the Average User

  • Change the Autosave Interval: define(‘AUTOSAVE_INTERVAL’, 30 ); (30 = 30 seconds)
  • Disable Post Revisions: define(‘WP_POST_REVISIONS’, false );
  • Modify Empty Trash Time: define(‘EMPTY_TRASH_DAYS’, 7 ); (7 = 7 days)
  • Auto Optimize Your Database: define(‘WP_ALLOW_REPAIR’, true);
  • Enable the Cache:define(‘WP_CACHE’, true);
  • Define Maximum # of Revisions:define(‘WP_POST_REVISIONS’, 5);

Help for Developers

  • Output Errors:define(‘WP_DEBUG’, true);
  • Save Queries for Analysis:define(‘SAVEQUERIES’, true);
  • Define WP Site URL (override settings):define(‘WP_SITEURL’, ‘http://’ . $_SERVER[‘SERVER_NAME’] . ‘/path/to/wordpress’); – great for moving sites from one host to another when the actual domain name is not yet available
  • Define WP Home (override settings):define(‘WP_HOME’, ‘http://’ . $_SERVER[‘HTTP_HOST’] . ‘/path/to/wordpress’); – great for moving sites from one host to another when the actual domain name is not yet available

Full documentation is available: http://codex.wordpress.org/Editing_wp-config.php

HOWTO: Add a Custom Comment Class to WordPress

Ever need to add your own class to your WordPress comment template but not sure how because of the function comment_class that controls the classes? Check out the function comment_class and you will see adding your own custom classes very easily.

Allow this sounds pretty basic – it is a lifesaver for doing a lot of customizations.

WordPress: Keep Up to Date – No Excuses

Over the past few days, there has been a lot of buzz going around about keeping WordPress up to date because of a specific worm going around that is causing havoc for out of date WordPress versions. The worm creates a user, hides it from the user list, and then inserts all kinds of junk into your posts.

There are multiple ways to easily find out when WordPress has been updated.

Since everyone who uses WordPress should stay on top of these updates, here are a few ideas on how to find out when a new version has been released:

  1. Pay attention the the “Upgrade Now” notice when you log into WordPress.
  2. Get notified by email with the Upgrade Notification by Email plugin
  3. Read regularly/subscribe to the WordPress blog
  4. Read regulary/subscribe to this blog

Updating is quick and easy – and should always be done after you have a database backup. Database backups are quick and easy as well with WP-DB-Backup plugin.

Not really sure if you want to do the upgrade yourself? We would be happy to do it for you – just contact us.

WordPress 2.8.4 is Available

WordPress 2.8.4 has officially been released. The update contains an important security update and updating is highly recommended. You can read more about all the changes and updates that went into 2.8.4 if you are interested. You can also see all the bug fixes as well.

Download the latest versions of WordPress: WordPress 2.8.4

WordPress 2.8.3 is Available

WordPress 2.8.3 has officially been released. The update contains a few important security updates and updating is highly recommended. You can read more about all the changes and updates that went into 2.8.3 if you are interested. You can also see all the bug fixes as well.

Download the latest versions of WordPress: WordPress 2.8.3