WP_Query custom order and pagination

You want to orderby ‘date’ not by ‘meta_value_num’ because it is to order numerically. So if you were ordering items by their price, then you would want to use ‘meta_value_num’. The meta_key ‘news_date’ is most likely in date format. You should also cast the meta_value to DATE using ‘meta_type’ => ‘DATE’. $args = array( ‘post_type’ … Read more

Filter out a meta key in the Search results page with two CPT

You could add a second array to check if the ‘DTEND’ value is not set: $args = array_merge( $wp_query->query_vars, array( ‘meta_query’=> array( ‘relation’ => ‘OR’, array( ‘key’ => ‘DTEND’, ‘compare’ => ‘>=’, ‘value’ => $currentdate, ), array( ‘key’ => ‘DTEND’, ‘compare’ => ‘NOT EXISTS’, ) ), ) ); That way, any custom posts without a … Read more

Trying to get property of non-object in: $wp_query

get_object_vars() returns an associative array of object properties – so queried_object is never in $wpQueryObj, it’s a key: $wpQueryObj[‘queried_object’]. Besides, you shouldn’t be doing any of that anyway – use get_queried_object(): if ( $wp_query instanceof WP_Query ) { if ( $object = $wp_query->get_queried_object() ) { $query_name = isset( $object->name ) ? $object->name : ”; } … Read more

WP_query is not returning the expected result

Try using this: $args = array( ‘post_type’ => YOUR_POST_TYPE, ‘meta_query’ => array( array( ‘key’ => ‘_wpcf_belongs_marque-type_id’, ‘value’ => $parent_id ) ) ); In your loop set an else statement just to sure that you query isn’t returning zero results: if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $output .= ‘<li class=”active-results”>’ . … Read more

All Posts Have The Same Comments

You are stomping on the global wordpress posts with your plugin. Doing your wp_query call and then calling $recent_articles_wtb->the_post(); means that later (after your loop), you will want to call wp_reset_postdata(); # Thanks Milo That should reset the global $current_post and $post objects.

Query Taxonomy By Page Title

If you don’t define the field in the array then it defaults to ID. Your options are term_id, name and slug: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters ‘tax_query’ => array( array( ‘taxonomy’ => ‘language’, ‘field’ => ‘name’, ‘terms’ => get_the_title() ) )

How to show list of posts with custom field value (a date) that are coming soon

Firstly, the_post() doesn’t actually output anything – it just sets up the post data ready to output. You’ll need to do something like this to show the posts: <?php while ( $loop->have_posts() ) : $loop->the_post(); the_title(); the_content(); endwhile; ?> There’s several more tags you can use and you’ll want to format the HTML around them … Read more