我尝试将get_results()转换为WP_Query(),但不知道如何。
获取结果:
$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 );
有可能吗?感谢您的任何建议
答案 0 :(得分:0)
美好的一天,试试这个:
$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 );