I’ve quickly tested the below code with a small subset of sendouts
( 3 ) and changing the publishing date of my page that uses this template it works fine
<?php
/**
* Template Name: show sendouts template
*
*/
get_header();
global $wpdb, $post;
$curDate=strtotime(date('Y-m-d H:i:s'));
$postDate=strtotime($post->post_date);
$pageAge=($curDate-$postDate) / (60 * 60 * 24); // age of the page in days
$steps= 14; // days used as interval between the steps
$totSteps= intval($pageAge / $steps); // how many steps passed from the page publishing date
$Q = "SELECT ID, post_title FROM ".$wpdb->prefix."posts where post_type="sendout" and post_status="publish" ORDER BY post_date ASC LIMIT ".($totSteps + 1);
$sendouts=$wpdb->get_results($Q);
$dropDownoptions=[];
$dropDownoptions[]='<option value="" selected>Pick a sendout</option>';
for($k = 0 ; $k < count( $sendouts) ; $k ++){
if($totSteps == $k ){
// use the post which corresponds to the current step as main post
$mainPost =get_post($sendouts[$k]->ID);
}
else{
// use the others to populate the dropdown
$dropDownoptions[]= '<option value = "'.get_the_permalink($sendouts[$k]->ID).'">'.$sendouts[$k]->post_title.'</option>';
}
}
// MAIN CONTENT
echo '<h1>'.$mainPost->post_title.'</h1>';
echo '<p>'.$mainPost->post_content.'</p>';
?>
<!-- DROPDOWN-->
<select id="sendout_select"><?php foreach($dropDownoptions as $option){echo $option;}?></select>
<script>
jQuery(function(){
// bind change event to select
jQuery('#sendout_select').on('change', function () {
var url = jQuery(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
<?
get_footer();