C
C
Cyril2018-04-30 17:25:33
WordPress
Cyril, 2018-04-30 17:25:33

WordPress. get_posts compare with ID value?

how to make wp_query fetch with compare id?
to exclude if id is greater than or equal to 15 for example?

$currentid = 15;

  $query = get_posts(array(
    'post_type' 	=> 'posts',
    'orderby'     	=> 'ID',
    'order'       	=> 'DESC', 
    'exclude' 		=> $currentid, 
    'fields'             => 'ids', 
    'meta_query' => array(
      array(
        'key'     => 'ID',
        'value'   => $currentid,
        'compare' => '>='
      )
    )
  ));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2018-05-01
@HeadOnFire

1. Firstly, meta_query makes a subquery on the wp_postmeta table, not wp_posts, and there is no ID field in the wp_postmeta table - there are post_id and meta_id.
2. To solve your problem , the posts_where filter is suitable , with which you can add a WHERE ID >= $currentid.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question