Ordering terms before displaying posts

You could use tax_query to get only the posts with the term that is currently being looped. $argsPost = [ ‘post_type’ => ‘meal’,//CPT meal ‘posts_per_page’ => -1, ‘meta_key’ => ‘ordre’, ‘orderby’ => ‘meta_value’, // Use the custom post order ‘order’ => ‘ASC’ ‘tax_query’ => array( array( ‘taxonomy’ => ‘cat_meal’, ‘field’ => ‘term_id’, ‘terms’ => $term->term_id, … Read more

Meta query with order by another custom field

After fiddling and searching a bit I managed to have: ‘selected’ 10 posts on top ‘remaining’ posts below sorted descending by date Unfortunately the ‘selected’ posts are in descending order … here is my query: $args = array( ‘post_type’ => array( ‘projekty’, ‘publikacje’, ‘wystawy’, ‘wyklady’ ), ‘post_status’ => array( ‘publish’ ), ‘meta_query’ => array( ‘relation’ … Read more

Define orderby in url

adding this in the functions.php file works. Just remember to re-save your permalinks & empty the cache a few times to see the changes. add_action( ‘init’, ‘wpse13483_init’ ); function wpse13483_init() { add_rewrite_rule( ‘category/(.+?)/orderby/([^/]+)?/?$’, ‘index.php?category_name=$matches[1]&orderby=$matches[2]&order=asc’, ‘top’ ); add_rewrite_rule( ‘category/(.+?)/orderby/([^/]+)/order/([^/]+)?/?$’, ‘index.php?category_name=$matches[1]&orderby=$matches[2]&order=$matches[3]’, ‘top’ ); // with pagination; add_rewrite_rule( ‘category/(.+?)/orderby/([^/]+)/order/([^/]+)/page/([0-9]{1,})?/?$’, ‘index.php?category_name=$matches[1]&orderby=$matches[2]&order=$matches[3]&paged=$matches[4]’, ‘top’ ); }

Order by meta_key with two meta_queries

You can do this using WP_Query since 3.1 with a meta_query. $args = array( ‘meta_key’ => ‘_count-views_all’, ‘orderby’ => ‘meta_value_num’, ‘order’ => $sortOrder, ‘posts_per_page’ => 9, ‘paged’ => $paged, ‘meta_query’ => array( ‘relation’ => ‘OR’ array( ‘key’ => ‘contributorid1’, ‘value’ => $id, ‘compare’ => ‘=’ ), array( ‘key’ => ‘contributorid2’, ‘value’ => $id, ‘compare’ => … Read more

How to order by blog ID in this multisite ‘List Blogs’ custom function

The following query works. Note the quotes in AND blog_id != ‘1’ global $wpdb; $query = ” SELECT blog_id FROM $wpdb->blogs WHERE site_id = %d AND public=”1″ AND archived = ‘0’ AND mature=”0″ AND spam = ‘0’ AND deleted = ‘0’ AND blog_id != ‘1’ ORDER BY blog_id ASC”; $blogs = $wpdb->get_col( $wpdb->prepare( $query, $wpdb->siteid) … Read more

orderby=meta_value_num creates duplicate posts

As for the edit (leading zeroes): /* will print “001” */ echo sprintf( “%03d”, 1 ); /* will print “00097” */ echo sprintf( “%05d”, 97 ); As for the inital problem: Obviously, I believe your problem description, but if ‘orderby’ => ‘meta_value’ does not produce duplicate results, neither should a change to ‘orderby’ => ‘meta_value_num’. … Read more

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