Orderby the sum of several numeric custom meta fields

This is definitely not within realm of native orderby parameters in query. They are limited to an order by individual meta fields and have no ways to implement aggregate of them. You would have to either write custom SQL for it or query a broader set and finalize calculations on PHP side. It is hard … Read more

Show one item per category of a custom post type

$args = array( ‘taxonomy’ => ‘portfolio_type’, ‘exclude’ => ‘28,30’, ); $tax = get_terms($args); foreach($tax as $t){ echo ‘<div class=”span3 produto-lista”>’; $args = array( ‘tax_query’ => array( array( ‘taxonomy’ => ‘portfolio_type’, ‘field’ => ‘slug’, ‘terms’ => array($t->slug) ) ), ‘posts_per_page’ => 1, ‘post_status’ => ‘publish’, ‘order’ => ‘DESC’, ); $query = new WP_Query( $args ); while … Read more

How to build a WP_Query using mulitple tags and using AND or OR operator between them

Give something like this a try: (it came from the same page you linked to, just scroll down a bit more). $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, // searches for posts meeting both conditions array( ‘taxonomy’ => ‘midgets’, ‘field’ => ‘slug’, ‘terms’ => array( ‘tagA,TagB’ ), // searches for … Read more

Adding an array from a query string to a WP meta_query

This $_GET[‘variable’] is an array, as per your URL query string ?variable[]=value1&variable[]=value2, $_GET[‘variable’][0] and $_GET[‘variable’][1] should return those 2 key values Edit – after the discussion – making it dynamic $meta_query = array(); if ( ! empty( $_GET[“variable”] ) ) { if ( is_array( $_GET[“variable”] ) ) { $meta_query[‘relation’] = ‘OR’; foreach ( $_GET[“variable”] as … Read more

I want to get title name of post, but i didn’t get by this code. Any suggestion?

Use this code: $args = array( ‘post_type’ => ‘food’, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘listing_price’, ‘order’ => ‘DESC’, ‘posts_per_page’ => $count, ‘paged’ => $paged, ); $loop = new WP_Query( $args ); if ( $loop->have_posts() ): while ( $loop->have_posts() ) : $loop->the_post(); echo get_the_title(); echo get_the_content(); endwhile; endif;

Populate tax_query terms parameter with post term

You have a couple of issues here. As your code stand, $post is undefined. It is actually better to make use of get_the_ID() to get the post ID instead of $post wp_get_post_terms() makes an extra db call, so if you are really set on performance, I would rather use get_the_terms() You are returning term names, … Read more