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

  • estevaoacioli
    Participant
    # 6 months, 3 weeks ago

    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
    # 6 months, 3 weeks ago

    Hello,

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

    estevaoacioli
    Participant
    # 6 months, 3 weeks ago

    Yes, that’s it

    estevaoacioli
    Participant
    # 6 months, 3 weeks ago

    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.