single post navigation order (NOT chronological)

after a lot of trial and error WP transients came to save me!!

here is the solution for anyone that might need this…

in the index.php (outside the main loop) i save the current random order in a transient:

$order_array = array();
while ( $the_query->have_posts() ) :
    $the_query->the_post();
        $order_array[] = get_the_ID() ;
endwhile;

set_transient('post_order', $order_array, 100);
// the expiration can be whatever you want

// Restore original Post Data
wp_reset_postdata();

now in the single.php where i add the next and prev navigation functionality:

            $next_post_index = $current_post_index+1;
            echo "<br> next post index : " . $next_post_index;
            $next_post_id = $array[$next_post_index];
            echo " id: " . $next_post_id;
            if($next_post_id != '') {echo "<br><a href="https://wordpress.stackexchange.com/questions/105100/. get_permalink( $next_post_id ) .">next</a>";}

            $previous_post_index = $current_post_index-1;
            echo "<br> previous post index : " . $previous_post_index;
            $previous_post_id = $array[$previous_post_index];
            echo " id: " . $previous_post_id;
            if($previous_post_id != '') {echo "<br><a href=" . get_permalink( $previous_post_id ) . ">previous</a>";}

this has a bit of extra markup because i was echoing everything along the way to check if it was working. i am sure that it can be cleaned up, but it works! and it does not display next or prev if there is no other post before or after it (i.e. first post only shows ‘next’ link)

yay, it works 🙂