Monthly Archives: May 2010

Filters to Modify a Query

UPDATE: See the excellent variation by keesiemeijer here:

Many times it is necessary to use a filter to modify a query.  For example, you may want to include a column that WP does not normally include in a query.  Or, you may want to do some complex selection of posts based on criteria that query_posts does not supply.  Continue reading

First and Last Post on a Page

If you want to detect the first and last post on a page (not the entire query), you can use the code below:

if (have_posts()) : while (have_posts()) : the_post();
  if( $c == 1 ) {
  } elseif ( $c == $wp_query->post_count ) ) {
  // Rest of the code for the Loop

Select meta_value between limits

This code was written for a user to select posts based on the value of a Custom Field between min and max limits. Continue reading

Pagination of Array / Custom Query


As of WP 3.3.1, I have had problems using this approach with pretty permalinks. Please use the paginate_links() technique instead.

The mam_paginate() function shown here can be used to paginate a Custom Query or any array. I use it instead of paginate_links() when I want more control over the output. It can also be used outside of WordPress with only slight modification. Continue reading

Child Theme

Child themes are a great way to customize a theme without the chance of losing your changes when the theme is updated. Here are some resources to explain how to use them:

A tutorial

Hide/Display Widgets on Selected Pages

Here is a plugin to Hide or Display Widgets on selected pages: Hide/Display Widgets on Selected Pages

Here is a newer one that has been tested up to WP 3.1 Widget Logic

Using WP in an Existing Site

If you have an existing site, and you want all or part of it to look like your favorite WordPress theme, the Codex has some information about how to do that.

Useful SQL Queries

Here are some articles with SQL queries that may be useful:

13 Useful SQL Queries NOTE: this site appears to make IE8 hang.

Posts from Custom Query

This Codex article has a detailed explanation of how to create a template using a Custom Query:

Add [raw] shortcode to display code

NOTE: This code appears to fail in WP 3.0.  Use the SyntaxHighlighter Evolved plugin instead. Continue reading