Compare post-IDs within WP_Query? (Less than / Greater than)

I ended up using something like this: function filter_where( $where=”” ) { global $post, $prev_next; $the_ID = $post->ID; $where .= ” AND wp_posts.ID “; $where .= $prev_next==’next’ ? “< $the_ID” : “> $the_ID”; return $where; } add_filter( ‘posts_where’, ‘filter_where’ ); $nextProjQuery = new WP_Query( $filtered_query_args ); remove_filter( ‘posts_where’, ‘filter_where’ );

Including Custom Meta with posts_where query

Well I managed to solve this sort of… The answer was to use separate search input boxes for each custom field being searched. Here is my working solution if anyone ever stumbles across this. function display_all_products() { global $term; $term = trim(strip_tags($_POST[‘s’])); $refnoterm = trim(strip_tags($_POST[‘ref’])); $yrterm = trim(strip_tags($_POST[‘yr’])); if(!empty($_POST[‘s’]) || !empty($_POST[‘ref’]) || !empty($_POST[‘yr’])) { if(!empty($_POST[‘s’])) … Read more

posts_where Fails with More than One Custom Field in Query

Think about your query. You are asking that $wpdb->postmeta.meta_key be both “foo” and “bar”. That will never happen. If you ran this in a context where you’d get to read MySQL debugging data (PhpMyAdmin’s SQL console will do this) you would probably see a warning about an “impossible where clause”. You need to JOIN on … Read more

When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?

You want to make sure you’re only messing with the main query and not subsequent queries called from a plugin or in a template on the search page. In other words… if( !is_admin() && $query->is_search ) { should be if( !is_admin() && $query->is_search && $query->is_main_query() ) { See http://codex.wordpress.org/Function_Reference/is_main_query

How do I create my own nested meta_query using posts_where / posts_join?

Here is a rough outline of how you’d go about making a UNION work with WP_Query. add_filter( ‘posts_request’, function ($clauses) { $clauses = str_replace(‘SQL_CALC_FOUND_ROWS’,”,$clauses,$scfr); $scfr = (0 < $scfr) : ‘SQL_CALC_FOUND_ROWS’ : ”; $clause2 = $clauses; // manipulate this return “SELECT {$scfr} u.* FROM (({$clauses}) UNION ({$clause2})) as u”; }, 1, 2 ); Set up … Read more

Custom time range for the posts_where filter

You can set your own custom query vars in a query, then use that value to set a class variable that you later read in the filter: class WPA69844_where { var $days; public function __construct(){ add_action( ‘parse_query’, array( $this, ‘parse_query’ ) ); } public function parse_query( $query ) { if( isset( $query->query_vars[‘my_days_var’] ) ): $this->days … Read more

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