Skip Navigation

[Resolved] Creating a view that matches a CPT of EVENTS to todays date

This support ticket is created 3 years, 7 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.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 1 reply, has 2 voices.

Last updated by Jamal 3 years, 7 months ago.

Assisted by: Jamal.

Author
Posts
#2111077

Tell us what you are trying to do?
I have a CPT called ENTITY EVENT which has several fields to collect date related data.
Such as Month, Day of the Month, Day of the Week, Year, Calendar Era (AD/BC) etc.
I would like to create a view that would check against THE CURRENT DATE, and list all events that the CPT holds that match up with todays date information. So if a CPT has the month field filled in with January and the date of the month filled in with 25 then on the 25th of January I would like this VIEW to populate with that CPT. If a CPT has day of the week filled in with THURSDAY, then on Thursdays I would like that CPT to populate the VIEW.

Is there any documentation that you are following?
No

Is there a similar example that we can see?
No

What is the link to your site?
hidden link

#2111351

Hello and thank you for contacting Toolset support.

Well, this cannot be handled by Toolset, out of the box. It will require custom code to modify the view's query arguments. Read more about the wpv_filter_query here:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

You will need some code that will get the month, day, and day of the week from the current date, check these online threads:
- https://stackoverflow.com/questions/3768072/php-date-function-to-get-month-of-the-current-date
- https://stackoverflow.com/questions/2306460/getting-the-date-for-current-day-in-php
- hidden link
- hidden link

The custom code will need to modify the query arguments to build nested conditions, the first one should be an 'OR':

$query_args['meta_query'] = array(
    'relation' => 'OR',
    // handle same month, same day case
    array(
        'relation' => 'AND',
        // handle same day
        array(),
        // handle same month
    ),
    // handle same day of the week
    array()
);

Read more about the query arguments on this WordPress documentation article https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

Please note that custom code is out of the scope of the support forum. If you are not comfortable with programming, consider hiring a developer. Check the list of our partners here https://toolset.com/contractors/
https://toolset.com/toolset-support-policy/

I hope this helps. Let me know if you have any questions.