Use the below example code for meta query (‘meta_query’) with a search query (‘s’):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | $q1 = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1, 's' => $query )); $q2 = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'speel', 'value' => $query, 'compare' => 'LIKE' ) ) )); $result = new WP_Query(); $result->posts = array_unique( array_merge( $q1->posts, $q2->posts ), SORT_REGULAR ); $result->post_count = count( $result->posts ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.