Created
February 11, 2014 21:15
-
-
Save dcooney/8944353 to your computer and use it in GitHub Desktop.
WP Merged Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url = $_SERVER['REQUEST_URI']; | |
$parts = parse_url($url); | |
parse_str($parts['query'], $query); | |
$term = $query['term']; | |
$q1 = get_posts(array( | |
'post_type' => 'project', | |
'posts_per_page' => -1, | |
's' => $term, | |
)); | |
$q2 = get_posts(array( | |
'post_type' => 'project', | |
'posts_per_page' => -1, | |
'meta_query' => array( | |
array( | |
'key' => 'organizations', // name of custom field | |
'value' => $term, // matches exactly "123". | |
'compare' => 'LIKE' | |
) | |
) | |
)); | |
$merged = array_merge( $q1, $q2); | |
$post_ids = array(); | |
foreach( $merged as $item ) { | |
$post_ids[] = $item->ID; | |
//echo $item->ID.', '; | |
} | |
$unique = array_unique($post_ids); | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
$wp_query = null; | |
$args=array( | |
'post_type' => 'project', | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
'paged' => $paged, | |
'post__in' => $unique, | |
'posts_per_page' => '5', | |
); | |
if($wp_query->have_posts()) : | |
while ($wp_query->have_posts()) : $wp_query->the_post(); | |
echo 'Post Content Here'; | |
endwhile; | |
if(function_exists('cnkt_pagenav')) : cnkt_pagenav(); endif; | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment