How do I correctly get all posts within the last year using the query_posts function?

Hi @Ryan Long:

You have two problems:

  1. You need to wrap the result of date( 'Y-m-d' , $newdate ); in a SQL DATE() function, and
  2. You define $ayearago outside of the filter_where() function so it’s not in scope within the function. You need to move the code that sets $ayearago into the filter_where() function like this:
function yoursite_filter_where($where="") {
  $today = date('Y-m-d');
  $newdate = strtotime ( '-1 year' , strtotime ( $today ) ) ;
  $ayearago = date( 'Y-m-d' , $newdate );
  $where .= " AND post_date >= DATE('{$ayearago}')";
  return $where;
}

Let me know if that works for you…