Skip to content

Instantly share code, notes, and snippets.

@whyisjake
Created December 16, 2014 22:01
Show Gist options
  • Save whyisjake/6938221d9c658e58e8f5 to your computer and use it in GitHub Desktop.
Save whyisjake/6938221d9c658e58e8f5 to your computer and use it in GitHub Desktop.
<?php
// This is the ideal post, based on the current pointer.
$ideal = $query->posts[ $index ]->ID;
if ( in_array( $ideal, $used ) ) {
// If it is in the array, update the index to the next.
// What this doesn't have, is a way to go 2+...
$index++
}
// Grab the post.
$_post = $query->posts[ $index ];
// Update the pointer.
$index++;
@tollmanz
Copy link

<?php
function get_next_valid_post( $pointer, $posts, $used ) {
    $id = $posts[ $pointer ]->ID;
    if ( ! in_array( $id, $used ) ) {
        return $pointer;
    } else {
        $pointer++;
        return get_next_valid_post( $pointer, $posts, $used );
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment