簡體   English   中英

WordPress-通過比較ID獲取帖子

[英]Wordpress - Get posts by comparing ID

我試圖在Wordpress中檢索post_id < $number的帖子,所以我在文檔中尋找了它,並嘗試了以下代碼:

$args = array(
    'numberposts'       => 10,
    'posts_per_page'    => 10,
    'offset'            => 0,
    'orderby'           => 'id',
    'order'             => 'DESC',
    'post_type'         => 'post',
    'post_status'       => 'publish',
    array(
        'key'     => 'post_id',
        'value'   => '3000',
        'compare' => '<'
    )
);

$query = new WP_Query( $args );
$posts = $query->get_posts();

但是它沒有用(返回最后10個帖子而不比較ID),我找不到答案:(

所以,請告訴我該怎么做..

並在此先感謝..

使用以下查詢。 它將返回帶有所需數據的數組。

   global $wpdb;
    $results = $wpdb->get_results( "SELECT ID, post_title FROM $wpdb->posts WHERE ID < 10;" );

暫無
暫無

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

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