CodeHQ

Posts Tagged ‘Search’

|

Custom search form for WordPress

Friday, September 30th, 2016

Create a file named searchform.php and place this in the root of the theme folder. This will replace the default WordPress search form.

<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
    <input type="text" placeholder="<?php echo esc_attr_x( 'Search website...', 'placeholder' ) ?>"
            value="<?php echo get_search_query() ?>" name="s"
            title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>"/>
</form>

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

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 »

Display search term | WordPress

Friday, April 29th, 2016

<?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>"

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