How to Order Posts by Custom Fields?

var_dump your $args arguments: array(4) { [“cat”]=> string(7) “2,39,30” [“orderby”]=> string(14) “meta_value_num” [“order”]=> string(4) “DESC” [“meta_key”]=> string(12) “album_rating” } The second time you use a key, you overwrite the first time. You cannot build the array like that. The orderby parameter will take a space separated string, so this is closer: $args = array( ‘cat’ … 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)