Is there any way to get only the IDs of the posts in a query?

Tagged:
  • estevaoacioli
    Participant
    5 years ago #11074

    Hello, is there any way to get only the IDs of the posts in a query? I need only list the IDs resulting from the main search so that I can execute a new custom query. Relevance has a function that does this.

    global $ relevanssi_post_types;
    $init_ids = $ relevanssi_post_types;

    Is it possible to do something similar in wpsolr? Thank you

    wpsolr
    Keymaster
    5 years ago #11075

    Hello,

    You can loop on the global $wp_query->posts, to get the ID field.

    estevaoacioli
    Participant
    5 years ago #11076

    Yes, that’s it

    estevaoacioli
    Participant
    5 years ago #11078

    WOW

    I managed to make it work, thank you 😉

    Here is my solution:

    $post_ids = wp_list_pluck( $wp_query->posts, ‘ID’ );
    print_r($post_ids);

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.