Query Posts by date range with fixed beginning and end

You should probably add the filter, then use a new query, then remove the filter. function filter_where( $where ) { $where .= ” AND post_date >= ‘2012-03-01’ AND post_date <= ‘2014-03-01′”; return $where; } add_filter( ‘posts_where’, ‘filter_where’ ); $query = new WP_Query( array( ‘post_type’ => ‘shop_order’ ) ); while( $query->have_posts() ) : $query->the_post(); the_title(); the_content(); … Read more

Passing additional variables to a query

If you’re running a custom query like $blog_query, add them right in. If you are wanting to change the main query, use the pre_get_posts action to alter the function. add_action( ‘pre_get_posts’, ‘alter_blog_order’ ); function alter_blog_order( $query ) { if( $query->is_main_query() and $query->is_post_type_archive( ‘post’ ) ) { $query->set( array( ‘orderby’ => ‘post-title’, ‘order’ => ‘ASC’ ) … Read more

Getting Year & Date inside wpdb [duplicate]

You mention the Codex page for WP_Query but you are not using WP_Query. You are using wpdb. WP_Query is a very complicated class for querying the WordPress tables for post (CPT) data. wpdb is a lightweight wrapper around PHP SQL functions. With WP_Query you can pass arguments like monthnum because the WP_Query class converts the … Read more

Manipulating a query

You might try to add a posts_where filter in your pre_get_posts hook: function my_pre_get_posts( $q ){ if( $q->is_main_query() ) add_filter( ‘posts_where’, ‘my_posts_where’ ); return $q; } ! is_admin() && add_action( ‘pre_get_posts’, ‘my_pre_get_posts’ ); where function my_posts_where( $where ){ // your custom replacements on the $where string // … // remove the filter remove_filter( current_filter() , … Read more

meta_query compare not doing what I want it to do

Your code looks valid for me. The only thing you can try is ‘NUMERIC’ instead of ‘numeric’ and to cast $current to int as date() will return a string. $current = (int)date(‘Ymd’); To debug this further you can place this directly under your code: global $wpdb; var_dump( $wpdb->last_query ); You’ll then have the complete query … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)