Function using get_posts() with tax_query not working when called from functions.php

For testing purposes in your functions.php file, try this – add_action(‘init’, ‘my_test_get_all_bands’, 99); function my_test_get_all_bands(){ echo ‘<pre>’; print_r(get_all_bands()); echo ‘<pre>’; } As I was attempting to say in my comment to your question (and as Pieter Goosen explained rather better), if your taxonomies have not yet been registered then the tax_query portion of your get_all_bands() … Read more

Custom navigation : show posts in sets of 4

I’m not sure if this is going to solve your whole issue, but you can add the paged parameter to your current custom query. I don’t know why you have set the offset parameter. If your offset is 0, omit it completely Also, remember to reset your post data after your custom query. Try something … Read more

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.