Search
 
SCRIPT & CODE EXAMPLE
 

PHP

where post_type like

function title_filter( $where, &$wp_query )
{
    global $wpdb;
    // 2. pull the custom query in here:
    if ( $search_term = $wp_query->get( 'search_prod_title' ) ) {
        $where .= ' AND ' . $wpdb->posts . '.post_title LIKE '%' . esc_sql( like_escape( $search_term ) ) . '%'';
    }
    return $where;
}

$args = array(
    'post_type' => 'product',
    'posts_per_page' => $page_size,
    'paged' => $page,
    // 1. define a custom query var here to pass your term through:
    'search_prod_title' => $search_term,
    'post_status' => 'publish',
    'orderby'     => 'title', 
    'order'       => 'ASC'
);

add_filter( 'posts_where', 'title_filter', 10, 2 );
$wp_query = new WP_Query($args);
remove_filter( 'posts_where', 'title_filter', 10 );
return $wp_query;
Comment

PREVIOUS NEXT
Code Example
Php :: php check if variable is resource 
Php :: nested array in laravel 
Php :: php bin/console debug events 
Php :: how get end of array in foreach php 
Php :: php get sql update from session 
Php :: breaks the collection into multiple smaller collections Laravel 
Php :: upload laravel 
Php :: Éviter le spam de commentaires 
Php :: custom end-point request php-salesforce-rest-api 
Php :: laravel count soft delete data 
Php :: mysql php update sum same table 
Php :: php preg_match html cross origin 
Php :: obtener tipo 
Php :: wpdb insert or if exists update 
Php :: wc get_image() return image url 
Php :: markdown mail html rendering laravel 
Php :: xampp php 
Php :: js data php 
Php :: comment php laravel template blade 
Php :: orwhere raw where condtion 
Php :: Call to undefined method AppModelsespece::links() laravel 8 
Php :: php check if cli mode 
Php :: 0.01 bnb to php 
Php :: php notice: trying to access array offset on value of type bool in /usr/share/php/pear/rest.php on line 187 
Php :: removing public from laravel url 
Php :: delete file in s3 laravel 
Php :: Inject interface and not concrete class 
Php :: php get last 4 digits of string 
Php :: can we acces session variable in two files 
Php :: php shell_exec must be connected to a terminal 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =