This my first ever StackOverflow questions so go easy on me!
I have a jQuery UI Datepicker field that I want to use as a basic 'navigation' device to jump straight to a Wordpress Post specific to that date. There are 368 posts over an almost one year period.
I can succesfully use the datepicker to redirect to a url that is based around the date field, e.g:
domain.com/2020-11-07
however, the posts themselves don't use that URL, they have a unique number:
domain.com/365
Is there a way to conditionally change that? I'm currently working around this using .htaccess redirects, but I guess I should avoid that if possible? I'd rather get it working directs from the datepicker script.
One complication, is that the post URLs are not strictly sequential; there are a few duplicates resulting in some like 036, 036B. I'm guessing that rules out doing this in a clever way and means 368 conditional statements. I can create the code easily enough though, once I know what to do. Here's what I currently have for the basic redirect:
$("#datepicker")
.datepicker({
dateFormat: "yy-mm-dd",
onSelect: function(dateText) {
$(this).change();
}
})
.change(function() {
window.location.href = "/" + this.value;
});
Any advice gratefully recieved!
Many thanks!
2020-11-07
relates to365
. There needs to be some logical relationship.onBeforeShow
to perform a check and populate data.code
<?php $this = get_field('date'); if ($this == '2020-10-08') { $slug = '350'; } elseif ($this == '2020-10-09') { $slug = '351'; } elseif ($this == '2020-10-1-') { $slug = '351B'; } ?> <a href="domain.com/<?php echo $slug; ?>">Link</a>code