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 do i remove posts from a WP_Query so the pagination is right?

Rather than querying all posts and then only displaying those that match the criteria, query for posts that match the criteria. WP_Query allows you to do just that with its meta-key/meta-value attributes. For instance, to get posts where the custom field unreleased is to ‘false’, somewhere before the loop: global $wp_query; $customField = array( ‘meta_key’ … 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

Including Custom Meta with posts_where query

Well I managed to solve this sort of… The answer was to use separate search input boxes for each custom field being searched. Here is my working solution if anyone ever stumbles across this. function display_all_products() { global $term; $term = trim(strip_tags($_POST[‘s’])); $refnoterm = trim(strip_tags($_POST[‘ref’])); $yrterm = trim(strip_tags($_POST[‘yr’])); if(!empty($_POST[‘s’]) || !empty($_POST[‘ref’]) || !empty($_POST[‘yr’])) { if(!empty($_POST[‘s’])) … Read more