October 5, 2014 at 18:41
#30690
Moderator
Okay, I threw this together. Put it in your functions.php file. I’ve done some initial testing and seems to work. Let me know how it works out for you.
COPY CODE
/*add member results to live search */
function kleo_ajax_search()
{
//if "s" input is missing exit
if(empty($_REQUEST['s'])) die();
$output = "";
$defaults = array('numberposts' => 4, 'post_type' => 'any', 'post_status' => 'publish', 'post_password' => '', 'suppress_filters' => false);
$defaults = apply_filters( 'kleo_ajax_query_args', $defaults);
$query = array_merge($defaults, $_REQUEST);
$query = http_build_query($query);
$posts = get_posts( $query );
$members = bp_core_get_users(array('search_terms' => $_REQUEST['s'], 'per_page' => 4, 'populate_extras' => false));
//if there are no posts
if(empty($posts) && $members['total'] == 0)
{
$output = "<div class='kleo_ajax_entry ajax_not_found'>";
$output .= "<div class='ajax_search_content'>";
$output .= "<i class='icon icon-exclamation-sign'></i> ";
$output .= __("Sorry, no pages matched your criteria.", 'kleo_framework');
$output .= "<br>";
$output .= __("Please try searching by different terms.", 'kleo_framework');
$output .= "</div>";
$output .= "</div>";
echo $output;
die();
}
//if there are members
if ($members['total'] != 0) {
$output .= "<h4>Members</h4>";
$output .= "<div>";
foreach ( (array) $members['users'] as $member ) {
$image = '<img /> $member-> ID, 'width' => 25, 'height' => 25, 'html' => false)) . '" class="kleo-rounded" alt="">';
$link = apply_filters('kleo_custom_url', get_permalink($member->ID));
$classes = "format-".$format;
$output .= "<div class ='kleo_ajax_entry $classes'>";
$output .= "<div class='ajax_search_image'>$image</div>";
$output .= "<div class='ajax_search_content'>";
$output .= "<a>ID)."' class='search_title'>";
$output .= $member->display_name;
$output .= "</a>";
$output .= "</div>";
$output .= "</div>";
}
$output .= "<a>".__('View member results','kleo_framework')."</a>";
$output .= "</div>";
}
//if there are posts
$post_types = array();
$post_type_obj = array();
foreach($posts as $post)
{
$post_types[$post->post_type][] = $post;
if(empty($post_type_obj[$post->post_type]))
{
$post_type_obj[$post->post_type] = get_post_type_object($post->post_type);
}
}
foreach($post_types as $ptype => $post_type)
{
if(isset($post_type_obj[$ptype]->labels->name))
{
$output .= "<h4>".$post_type_obj[$ptype]->labels->name."</h4>";
}
else
{
$output .= "<hr>";
}
foreach($post_type as $post)
{
$format = get_post_format($post->ID);
if (get_the_post_thumbnail( $post->ID, 'thumbnail' ))
{
$image = get_the_post_thumbnail( $post->ID, 'thumbnail' );
}
else
{
if ($format == 'video') {
$image = "<i class='icon icon-video'></i>";
}
elseif ($format == 'image' || $format == 'gallery') {
$image = "<i class='icon icon-picture'></i>";
}
else {
$image = "<i class='icon icon-link'></i>";
}
}
$excerpt = "";
if(!empty($post->post_content))
{
$excerpt = "<br>".char_trim(trim(strip_tags(strip_shortcodes($post->post_content))),40,"...");
}
$link = apply_filters('kleo_custom_url', get_permalink($post->ID));
$classes = "format-".$format;
$output .= "<div class ='kleo_ajax_entry $classes'>";
$output .= "<div class='ajax_search_image'>$image</div>";
$output .= "<div class='ajax_search_content'>";
$output .= "<a href='$link'>";
$output .= get_the_title($post->ID);
$output .= "</a>";
$output .= "<span class='search_excerpt'>";
$output .= $excerpt;
$output .= "</span>";
$output .= "</div>";
$output .= "</div>";
}
}
$output .= "<a>".__('View all results','kleo_framework')."</a>";
echo $output;
die();
}
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com