WordPress.org

Support

Support » Plugins and Hacks » Relevanssi - A Better Search » [Plugin: Relevanssi – A Better Search] Filtering by post type after using 'seperating posts by

[Plugin: Relevanssi – A Better Search] Filtering by post type after using 'seperating posts by

Viewing 2 replies - 1 through 2 (of 2 total)
  • Also, I don’t need that post separation if a post_type parameter is supplied. So if an if statement can be applied to that code in functions.php, that would work too 🙂

    This code worked for me (provided by the developer). Just added this conditional around the original snippet:

    global $wp_query;
    	if ($wp_query->query_vars['post_type'] != 'post') {

    So the whole thing looks like this:

    add_filter('relevanssi_hits_filter', 'separate_result_types');
    function separate_result_types($hits) {
    
    	global $wp_query;
    	if ($wp_query->query_vars['post_type'] != 'post') {
    
    	    $types = array();
    
    	    // Split the post types in array $types
    	    if (!empty($hits)) {
    	        foreach ($hits[0] as $hit) {
    	            if (!is_array($types[$hit->post_type])) $types[$hit->post_type] = array();
    	            array_push($types[$hit->post_type], $hit);
    	        }
    	    }
    
    	 	if (!is_array($types['image'])) $types['image'] = array();
    	 	if (!is_array($types['video'])) $types['video'] = array();
    	 	if (!is_array($types['quote'])) $types['quote'] = array();
    	 	if (!is_array($types['topic'])) $types['topic'] = array();
    	 	if (!is_array($types['post'])) $types['post'] = array();
    
    	    // Merge back to $hits in the desired order
    	    $hits[0] = array_merge($types['video'], $types['image'], $types['quote'], $types['topic'], $types['post']);
    	    return $hits;
        }
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Relevanssi – A Better Search] Filtering by post type after using 'seperating posts by’ is closed to new replies.
Skip to toolbar