Skip Navigation

[Resolved] Showing posts in calendar view based on start of the day

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.

This topic contains 6 replies, has 2 voices.

Last updated by larryL 1 year, 7 months ago.

Assigned support staff: Waqar.

Author
Posts
#1795053

Hi Waqar, I was having a problem getting my calendar view to separate the posts. What it is doing is simply posting the entries over and over again on a weekly basis. I'm picking up where we left off (https://toolset.com/forums/topic/view-with-weekday-filtering/) Basically, instead of placing each daily entry in each column it's placing it in each row. So perhaps it's a simple solution that I'm not seeing.

#1796789

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for waiting.

To make the "date" type field's query filter work when the time information is also available, you'll need to make the following changes.

1. Instead of a single custom shortcode from Luo's message in another thread ( ref: https://toolset.com/forums/topic/how-to-filter-a-date-field-by-an-specific-day-of-the-week/#post-1124389 ), you'll need to register two custom shortcodes.
( one for the target day's start time and the other for the target day's end time )


add_shortcode('ts_day_week_start', function($atts){
    $atts = shortcode_atts( array(
        'day' => 'Monday',
    ), $atts);
    $res = strtotime('last ' . $atts['day']);
    if(date('l') == $atts['day']){
        $res = strtotime('this ' . $atts['day']);
    }
    return $res;
});


add_shortcode('ts_day_week_end', function($atts){
    $atts = shortcode_atts( array(
        'day' => 'Monday',
    ), $atts);
    $res = strtotime('last ' . $atts['day']);
    if(date('l') == $atts['day']){
        $res = strtotime('this ' . $atts['day']);
    }
    $res = strtotime("tomorrow", $res) - 1;
    return $res;
});

2. Next, please add "ts_day_week_start" and "ts_day_week_end" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

3. In the "Query Filter" section of the view, adjust the query so that it looks for number values between "tsstart" and "tsend" shortcode attribute.
( screenshot: hidden link )

4. Lastly, you'll update the shortcodes of the view for each day, to include these two shortcode attributes, instead of one.

For example, the existing shortcode for Friday looks like:


[wpv-view name="schedule-view" cached="off" ts="[ts_day_week day='Friday']"]

Updated shortcode for Friday, would be:


[wpv-view name="schedule-view" cached="off" tsstart="[ts_day_week_start day='Friday']" tsend="[ts_day_week_end day='Friday']"]

Likewise, you can update the shortcodes for the other days as well.

Important note: As explained earlier, 1-1 customization assistance is beyond the scope of support that we provide over the forum.
( https://toolset.com/toolset-support-policy/ )

Since your project's requirements have grown way too complex to be handled through the support forum, we'll have to request you to hire a professional, to assist you with any further custom code changes and troubleshooting.
( https://toolset.com/contractors/ )

I hope you'll understand.

regards,
Waqar

#1799113

Waqar,

The filter which takes the date/time field 'work start'... It looks between tsstart & tsend... and the function filters $res = strtotime('this ' . $atts['day']); I was trying to find that in the phpdocs but I didn't see a description.

Just so I understand what is going on here because it appears that even though it's set to be filtering by 'work start', I can't figure out how it is determining what posts to display. They don't appear to be using that field when it's displayed on the calendar.

Is there a document that would help me better understand the function?

Thanks!

#1802933

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

You can learn the details about the "strtotime" function in PHP from these links:
hidden link
hidden link

As the name indicates, the "ts_day_week_start" shortcode will give you the UNIX timestamp for the start of the provided weekday
( i.e. 12 am ) and the "ts_day_week_end" shortcode will give you the UNIX timestamp for the end of the provided weekday ( i.e. 11:59 pm ).

We need these two values because we need the posts which fall within these two, time values.

To make this more clear, you can test these shortcodes in a test page and convert the resulting UNIX timestamp values from any online converter like hidden link


[ts_day_week_start day='Friday']

[ts_day_week_end day='Friday']

#1803933

Thanks for this Waqar, I'm sorry one more thing. In the function you have :

 
    $res = strtotime('last ' . $atts['day']);
    if(date('l') == $atts['day']){
        $res = strtotime('this ' . $atts['day']);

however I can't find explanations for your usage. It could just be that I'm not yet advanced enough with PHP. Can I assume that all you're doing is defining which (day) the function will find from the unix string? Also, where in 'strtotime' does it allow you to 'lookup' specific dates based upon the string you pass to it? Sorry, I don't mean to be so dense. Looking at the examples provided:

<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>

it appears limited.

Thanks!

#1804069

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

> Can I assume that all you're doing is defining which (day) the function will find from the unix string?
- Yes, that is correct. The two example custom shortcodes that I shared, get a weekday from the shortcode attribute, and return that day's start and end times, respectively.

> Also, where in 'strtotime' does it allow you to 'lookup' specific dates based upon the string you pass to it?
- From the link that I shared with you earlier ( hidden link ):

"The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT)."

From the other link ( hidden link ), the "datetime" parameter that this "strtotime()" function accepts can be in any valid format supported by PHP:
hidden link

For any further explanation and background information related to this or any other PHP function, you can post your question at a specialist forum like Stack Overflow:
https://stackoverflow.com/

#1807837

My issue is resolved now. Thank you!