CodeHQ

Posts Tagged ‘Posts’

|

Custom post type at the top of WordPress search results

Monday, May 23rd, 2016

Paste this in to your functions.php file – this assumes your CPT is called ‘products’

add_filter( 'posts_search_orderby', function( $search_orderby ) {
    global $wpdb;
    return "{$wpdb->posts}.post_type LIKE 'products' DESC, {$search_orderby}";
});

Tags: , , , , ,
Posted in PHP, WordPress | No Comments »