WP_Query simple example

/**
 * Gets all draft post IDs.
 *
 * @see https://wpcodebook.com/wp_query-simple-example/
 * @see https://developer.wordpress.org/reference/classes/wp_query/
 */

$args = array(
	'post_status'    => 'draft',
	'posts_per_page' => -1,
	'fields'         => 'ids',
);

$query = new WP_Query( $args );

foreach ( $query->posts as $post_id ) {
	echo $post_id . '<br>';
}

Leave a Comment