[Resolved] Filter by custom date field to find posts from within the current month
This support ticket is created 8 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I use a shortcode to sum the values and then display them after the loop. This works fine if I don't try filter by date, I get the correct sum of all values. But as soon as I try to filter I get a result of '0'.
How do I filter a custom date field to only sum the values within the current month?
I have tried filtering by:
Select posts with custom field:
Start Date is a number equal to THIS_MONTH()
I have tried:
Select posts with custom field:
Start Date is a number in THIS_MONTH()
I have tried:
Select posts with custom field:
Start Date is a date in THIS_MONTH()
And I have tried:
Select posts with custom field:
Start Date is a date equal to THIS_MONTH()
None of these seem to work. I just get a value of 0 every time. Although I know I have posts with a date in this month and a value to sum. What am I doing wrong?
Sorry about the delay. I'm having a problem with my backup plugin, due to some php extension that is not installed, I'm waiting for my host to sort that out.
In the meantime I have discovered what the problem is. My filter is set to:
Select posts with custom field:
Start Date is a number between FUTURE_MONTH(1), FUTURE_MONTH(2)
What it is doing is including the post from 1 April. If I set the post start date to 2 April then it doesn't include it.
Is there any way to filter it so the date is greater than or equal to FUTURE_MONTH(1) AND less than FUTURE_MONTH(2) so it doesn't include the posts made on 1 April? I tried to add both of those filters, but it seems to only allow one filter per custom value.
Thanks, I think I almost understand what this is doing. Please correct me if I'm wrong.
This filter is applied to the view so I can choose which dates should be used yes?
I notice that the add-filter mentions the following function: 'posts_within_current_month'
But the function below is called 'posts_end_next_week'. I'm guessing these should be the same?
Also I'm not completely clear on what the two strtotime(date('Y-m-01')) in the value array are. Is this where I should be setting the two dates that I want to filter between?
So, I want to go from the 1st of the next month (ie March if I called it today), to the 31st of next month, can you tell me how I would write that?