简体   繁体   中英

Wordpress - Get posts by comparing ID

I'm trying to retrieve the posts in Wordpress that have post_id < $number , so I looked for it in the documentation, and tried this code :

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

but it didn't work (return the last 10 posts without comparing the ID), and I couldn't find an answer :(

So, could tell me please how to do it ..

And thanks in advance ..

Use the following query. it will return you array with your desired data.

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM