我只想获取所有具有比提供的帖子ID更大值的帖子
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'rid\',
\'value\' => $rid,
\'compare\' => \'=\',
\'type\' => \'numeric\',
),
array(
\'key\' => ID,
\'value\' => $last_id,
\'compare\' => \'>\',
\'type\' => \'numeric\'
),
),
因此,如果$last\\u id是“350”,我想获取所有id高于350的帖子
最合适的回答,由SO网友:Gufran Hasan 整理而成
您可以使用“准备”:
global $wpdb;
$post_ids = [];
$last_id = 350;
$query = $wpdb->prepare(
"
SELECT ID
FROM $wpdb->posts
WHERE ID > %d
", $last_id );
$results = $wpdb->get_results( $query );
// it will convert the IDs from row objects to an array of IDs
foreach ( $results as $row ) {
array_push( $post_ids, $row->ID );
}
//now you can set up your query
$custom_args = array(
\'posts_per_page\' => 100,
\'post__in\' => $post_ids
);
$custom_query = new WP_Query( $custom_args );
if( $custom_query->have_posts() ) :
while( $custom_query->have_posts() ) : $custom_query->the_post();
echo get_the_title() . \'<br>\';
endwhile;
endif;
Reference
Note: 您可以根据需要更改条件
>, >=, <, <=
等