WordPress: Display posts by custom select query

try this: $args = array( ‘post_type’ => ‘post’, ‘meta_query’ => array( array( ‘key’ => ‘Apple’, ‘value’ => ”, ‘compare’ => ‘NOT LIKE’ ) ), ‘meta_key’ => ‘Price’, ‘orderby’ => ‘meta_value_num’, ‘paged’ => get_query_var(‘paged’), ‘order’=> ‘DESC’, ); $the_query = new WP_Query( $args );

How to display a posts 1 year ago with custom WP_Query loop?

Filters allow you to change data as it is being used by the wordpress core. This is a huge part of what gives wordpress so much flexibility. add_filter() has 2 main parameters, the filter’s hook and the callback function. When the filter is executed, all the callbacks associated with that filter will be executed. Naturally, … Read more

How to fetch only media that was already attached to a post/page?

A similar approach to your post_parent idea is to add a filter to posts_where: function bbg_filter_out_non_attachments( $sql ) { global $wpdb; // Maybe do some conditional logic to decide whether to filter this query, then… return $sql . ” AND $wpdb->posts.post_parent != 0 “; } add_filter( ‘posts_where’, ‘bbg_filter_out_non_attachments’ ); Another technique is to do a … Read more

reducing the amount of wp_query calls

Rather than querying for a single item and then querying again for 6 more excluding the first, you can just do a single query for 7 items and selectively output markup by checking which post you’re currently outputting in the loop via $your_query_object->current_post. You can also combine that with $your_query_object->rewind_posts() to run through the same … Read more

Use query->set or make new query?

If you can alter a query before it runs, then do so and save the database some work. You might be able to alter the query with query->set() and if not you can use the posts_where, posts_fields, etc filters. It is hard to say whether any of that is best for you without more information. … Read more

Comparing dates in custom field

Your date format is in the wrong order. Think of it from a strictly numerical perspective- 11222012 > 1032013 Dates should follow the MySQL date format in descending units- yyyy-mm-dd

WP_Query Variable inside Array

Your array definitions aren’t correct. This… elseif($_REQUEST[“price”] == 20){$price = “array( ’19’, ’20’ )”;} … creates a literal string that reads “array( ’19’, ’20’ )”. Remove the quotes. elseif($_REQUEST[“price”] == 20){$price = array( ’19’, ’20’ );} That should give you PHP arrays.