I get two values from GET
$start = $_GET['start'];
$end = $_GET['end'];
These are:
1-11-2018
30-11-2018
Then I remove the dash
to create a whole number
$start = str_replace(["-", "–"], '', $start);
$end = str_replace(["-", "–"], '', $end);
Now we have:
1112018
30112018
Then we do a loop over our posts (we only have 2 posts) and we grab the value from a custom field:
$myDate = get_post_meta($id, 'usp-custom-80', TRUE);
Which gives us:
13-11-2017
26-11-2018
And then we do:
$myDate = str_replace(["-", "–"], '', $start);
And we have:
13112017
26112018
So now we can check if the value
we're getting from the custom field
is within or not the values
we have from GET
if (($myDate >= $start) && ($myDate <= $end)) {
//content....
But I am getting the logic wrong, also because the dates from GET
could have 1
without a zero
at the beginning 01
and the number would be less even tho the actual date is correct to be considered within it.
Any idea how I can check if $myDate
is in between $start
and $end
?
UPDATE
If I don't remove dash and I get:
Start date: 1-11-2018
End date: 30-11-2018
User date: 13-11-2017
And then I simply do:
if ( ( $myDate >= $start) && ( $myDate <= $end) ) {
I get ALL posts and not the filtered by range