The Genesis theme framework sets a global var $_genesis_displayed_ids
which is an array with all the displayed post IDs.
I needed this kind of data for a WordPress installation without Genesis. We have the function the_post() but we also have the action hook the_post, which helped me to retrieve the data.
This is the snippet that makes use of this action hook to retrieve all the IDs in a global var.
1 2 3 4 5 6 7 8 | add_action( 'the_post', 'set_displayed_items' ); public static function set_displayed_items( $post_object ) { global $_displayed_ids; $_displayed_ids[] = $post_object->ID; } |
How to set a global var for all displayed post IDs like Genesis