How to combine two or more WP_Query?

Hope this code may work for you. $query1 = new WP_Query( array( ‘post_type’ => ‘product’, ‘s’ => $searchStr )); $query2 = new WP_Query( array( ‘post_type’ => ‘product’, ‘meta_query’ => array( array( ‘key’ => ‘my_meta_key’, ‘value’ => $searchStr, ‘compare’ => ‘LIKE’ ) ) )); $result = new WP_Query(); $result->posts = array_unique( array_merge( $query1->posts, $query2->posts ), SORT_REGULAR … Read more

Changing WP_Query params with url Query Var

This code manually sets the order with the ‘order’ => ‘ASC’ declaration in the WP_Query arguments. $loop = new WP_Query( array( ‘post_type’ => ‘product’, ‘meta_key’ => ‘product_price’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘posts_per_page’ => 4, ‘paged’ => $paged) ); If we want to pass a url parameter to that we could use something like: … Read more

How to display upcoming events by dat with Modern Events Calendar Lite

i have found a solution, making a custom SQL query here is the code ( using WPML ) $startday = date(“Y-m-d”); if ( defined( ‘ICL_LANGUAGE_CODE’ ) ) { $lang = ICL_LANGUAGE_CODE; } //echo $startday; global $wpdb,$post; $results = $wpdb->get_results( “SELECT * FROM wp_posts, `wp_mec_dates` AS mecd, wp_icl_translations WHERE wp_posts.ID = mecd.post_id and post_status=”publish” AND wp_icl_translations.language_code=”$lang” … Read more

List of the years with posts presented

Relationship between post and category is not stored in the posts table. You must extend your query for additional tables. By category id: SELECT YEAR(p.post_date) FROM {$wpdb->posts} p JOIN {$wpdb->term_relationships} tr ON tr.object_id = p.id JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id = tr.term_taxonomy_id WHERE tt.term_id = 4 AND p.post_status=”publish” AND p.post_type=”post” GROUP BY YEAR(p.post_date) DESC Or … Read more

new WP_Query with author argument return no results

Whenever you use capability_type you need to then assign those capabilities to the roles which should have access to the post type; Otherwise they will not have access to the post type. Awhile back Justin Tadlock wrote an article around capbility_type: Meta Capabilities For Custom Post Types. If you don’t want to have to assign … Read more

WP_Query To call data from diffrent tables

How can i join my request and get data from multiple tables You don’t, instead, you break it into multiple steps, and retrieve by individually For example, lets say I want to list the top 5 posts, and display a piece of user meta about their authors, e.g. a score. That can’t be done in … Read more

Redirect page when URL parameter not set

However, to solve the issue, it seems the answer is to check the queried object is not NULL $query->get_queried_object() !== NULL I had to remove the query_var because it turned the homepage into a 404. A separate issue. // redirect if there’s no job id function redirect_to_pending($query) { if($query->get_queried_object() !== NULL && $query->is_page(26)) { if(!isset($_GET[‘shazzid’])) … Read more