Skip Navigation

[Resolved] Views custom field filter by current day of week – TODAY(l)

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

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

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Suzanne Wenger 4 years ago.

Assisted by: Shane.

Author
Posts
#1565429

I am trying to filter a view to only show results (event posts) based on the current day of the week. I don't want to have to build a custom shortcode for this if I don't absolutely have too, as my site file access is limited.

Is there a way to use the Types date filter of TODAY() or DATE() to load just the day? For example to do something like TODAY(l) to pull the current day of the week?

Thanks,
Suzanne

#1566101

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Suzanne,

Thank you for getting in touch.

Not sure I understand your query completely.

You want to filter your view by the current day. Meaning you only want posts that have their custom field set to a date like today to be displayed in the view ?

Secondly you want to display what day it is on you view ?

Please clarify for me.

Thanks,
Shane

#1567863

Hi Shane,
Sorry for the delayed response...

I want to show event posts that are assigned to the same day in the week as the current date's day of the week. There are events that are checked to happen recurring on Mondays and Wednesdays and other events that recur on Tuesdays and Thursdays for example.

I have a custom field "Days of the Week" which lists all the days of the week, and I can tag which days of the week the event recurs.

I want to filter these events by the current day of the week...meaning... if day_of_week_custom_field = TODAY (day of the week) or if Monday = Monday. TODAY() being today's date, but only capturing the actual day of the week the PHP "l".

Hope this clarifies for you,
Suzanne

#1568439

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

shortcode attribute.PNG

Hi Suzanne,

Thank you for the clarity.

You Days of the week field isn't a Date field but rather a custom field that list out the days. In a case like this you won't be able to use this view filter as its the function returns a timestamp.

You will need to use this custom shortcode below to get today's date

// Add Shortcode
function wp_today_day() {

	return date("l");
	

}
add_shortcode( 'wp_today_day', 'wp_today_day' );

Add this shortcode to the custom code section in Toolset -> Settings -> Custom Code. From there just activate it.

The shortcode is used like [wp_today_day]

So for your date filter you will need to set the filter to be filtered by a shortcode attribute. See Screenshot

Once you've done that the next thing you need to do is to register the shortcode so that it can be used as a view attribute. Go to Toolset->Settings->Frontend then scroll to 3rd party shortcode arguments and register the shortcode name there.

Finally just call your view with the field and the shortcode.
[wpv-view name='[wp_today_day]']

Please let me know if this helps.
Thanks,
Shane

#1584099

Hi Shane,
Sorry I didn't respond for a while to your final post on this support request. Thank you so much for your help. The custom shortcode worked well. I called the shortcode in the end with the following [wpv-view name="my-view-name" myattribute="[wp_today_day]"].

Cheers,
Suzanne

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.