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

Pagination on custom query

Add this to your query: ‘paged’ => get_query_var(‘paged’) Like so: $args = array( ‘post_type’ => ‘species’, ‘meta_query’ => $meta_query, ‘tax_query’ => $tax_query, ‘paged’ => get_query_var(‘paged’) ); Should do the trick.. Using Wp-pageNavi? dont forget to add the wp-pagenavi tag just after the loop ends <div class=”navigation”><?php wp_pagenavi(); ?></div> . Hope This Helps 😉 Cheers, Sagive.

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

Query 1 taxonomy term, exclude another

I guess its because you are trying two conditions on one taxonomy, you can allways create a custom sql query, something like this: $querystr = ” SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id) WHERE $wpdb->posts.post_type=”resource” AND $wpdb->posts.post_status=”publish” AND $wpdb->term_taxonomy.taxonomy = … Read more

How to get 4 Posts after the 5 most recent ones

Simple. WordPress provides a function called get_posts() that lets you get posts in any order. Basically, get_posts() will retrieve the 5 most recent posts by default. To get 4 posts, ignoring the 5 most recent, you’d set the numberposts and offset parameters – offset tells the function how many posts to skip. $args = array( … Read more

How to order posts by slug using query_posts/ Wp_query

In WordPress the post slug is saved in database with name post_name, so to sort posts by slug just use: orderby=name. Edit: Here’s the example of query: $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 10, ‘orderby’ => ‘name’ ); $query = new WP_Query( $args );

exclude ids through post__not_in

Your PHP is wrong. function slider_exclude(){ $exclude_query = query_posts(array(‘showposts’ => 4, ‘cat’ => ‘news’,)); foreach($exclude_query as $post_ids){ return $post_ids->ID.’,’; } } Looks like you are trying to build a comma delimited string but that isn’t how return works. When that foreach hits the return the function returns– it ends. Nothing else gets processed. You need … Read more