I try to transform get_results() to WP_Query(), but do not know, how.
get result:
$myposts = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->posts
WHERE post_type = 'advertisements'
AND post_title != 'Automatický koncept'
and post_title LIKE '%s'", '%'. $wpdb->esc_like( $text ) .'%') );
WP_Query() :
$args = array('post_type' => 'advertisements',
'posts_per_page' => 2,
);
$wp_query = new WP_Query( $args );
Is that possible? thanks for any advice
Good day, try this:
$args = array(
'post_type' => 'advertisements',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'post_title',
'value' => 'Automatický koncept',
'compare' => '!=',
),
array(
'key' => 'post_title',
'value' => '%' . $wpdb->esc_like( $text ) . '%',
'compare' => 'LIKE',
),
),
);
$wp_query = new WP_Query( $args );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.