meta_query only check if both value are set

You can use isset to check if the values are set, and then pass them as arguments. Divide your query by 2 parts and use them as needed. // Check if both are set if ( isset( $max_age ) && isset( $min_age ) ) { $meta_query = array( ‘relation’ => ‘AND’, array( ‘key’ => ‘min_age’, … Read more

Order & Orderby clause not working with custom query

Sorting your posts by relevance. The code below will output the posts ordered by relevance I have added some comments for some clarification let me know if it works. function my_custom_query(){ // get only the posts without order them $my_query_posts = new WP_Query( array( ‘numberposts’ => 5 ) ); // check relevance posts foreach( $my_query_posts->posts … Read more

WP_Query to Retrieve Posts from WooCommerce Products that are Only in Catalog

Posted too quick. Found a solution shortly after This works: $params = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘product’, ‘orderby’ => ‘menu-order’, ‘order’ => ‘asc’, ‘fields’ => ‘ids’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_visibility’, ‘field’ => ‘term_id’, ‘terms’ => 7, ‘operator’ => ‘NOT IN’) )); $wc_query = new WP_Query($params); $ids = $wc_query->posts; echo ‘<pre>’; … Read more

Paginated Author.php not using Author.php template

This is not fix for your issue is only an working example of what you can use for the author.php page. <?php $number = 10; $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $offset = ($paged – 1) * $number; $users = get_users(); $query = get_users(‘&offset=”.$offset.”&number=”.$number); $total_users = count($users); $total_query = count($query); $total_pages = intval($total_users / … Read more

WP Query Meta Query

I think the orderby key is at the wrong place. It think it should be like this: $args = array( ‘post_type’ => ‘event’, ‘order’ => ‘ASC’, ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘your key to order’, ‘meta_query’ => array( ‘key’ => ‘Date Ordering Format’, ‘relation’ => ‘AND’, array( ‘key’ => ‘Event Type’, ‘value’ => ‘4. take-out … Read more