Created
April 6, 2015 21:58
-
-
Save hellofromtonya/866862794445bc4c87bf to your computer and use it in GitHub Desktop.
Get all Post IDs for the current WP_Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'loop_end', 'tonya_get_list_of_post_ids_in_current_loop' ); | |
/** | |
* Get a list of Post IDs for the current Loop. | |
* | |
* Hooks into 'loop_end' which occurs when WP_Query is done with the | |
* loop (see wp-includes/query.php). | |
* | |
* @since 1.0.0 | |
* | |
* @param WP_Query obj $query WP_Query object instance | |
* @return void | |
*/ | |
function tonya_get_list_of_post_ids_in_current_loop( $query ) { | |
$ids = array(); | |
foreach ( $query->posts as $post ) { | |
$ids[] = $post->ID; | |
} | |
//* Now do something with it. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment