簡體   English   中英

如何獲取類似get_results()的搜索查詢到Wp_Query以獲取我的帖子?

[英]How to get search query like in get_results() to Wp_Query for my posts?

我嘗試將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 );

那可能嗎? 感謝您的任何建議

美好的一天,試試這個:

$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 );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM