Generate an array of post IDs in current query

<?php
global $wp_query;
$posts = wp_list_pluck( $wp_query->posts, 'ID' );
view raw functions.php hosted with ❤ by GitHub

Returns an array of post IDs in the main query. Useful when doing a secondary query and you don’t want to have duplicate posts.

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk