Skip to content

WP Query search filter using get native php function or post method from input field for advance search from post and custom post type.

Notifications You must be signed in to change notification settings

nielsoffice/WPQuery_Search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 

Repository files navigation

WPQuery_Search

WP Query search filter using get native php function or post method from input field for advance search from post and custom post type.

<?php 

function title_filter($where, &$wp_query){
    global $wpdb;

    if($search_term = $wp_query->get( 'search_prod_title' )){
        /*using the esc_like() in here instead of other esc_sql()*/
        $search_term = $wpdb->esc_like($search_term);
        $search_term = ' \'%' . $search_term . '%\'';
        $where .= ' AND ' . $wpdb->posts . '.post_title LIKE '.$search_term;
    }

    return $where;
}

$args = array(
    'post_type' => 'post',
    's'         => $search_terms,
    'post_status' => 'publish',
    'orderby'     => 'title', 
    'order'       => 'ASC'        
);

$wp_query = new WP_Query($args);

?>

Reference:
WordPress The Loop Fetch Data From Database WP_Query/PHP
By Ashan Jay

About

WP Query search filter using get native php function or post method from input field for advance search from post and custom post type.

Topics

Resources

Stars

Watchers

Forks