Skip Navigation

[Résolu] ts_day_week filter not working

This support ticket is created Il y a 4 années et 1 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Marqué : 

Ce sujet contient 10 réponses, a 2 voix.

Dernière mise à jour par larryL Il y a 4 années et 1 mois.

Assisté par: Shane.

Auteur
Publications
#1783727

I have


add_shortcode('ts_day_week', 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;
});

as recommended by Luo in my functions.php and


<div class="main-calendar-wrapper">
    <div class="calendar-item">
        <div class="calendar-item-head">FRI</div>
        <div class="calendar-item-body">[wpv-view name="schedule-view" cached="off" ts="[ts_day_week day='Friday']"]</div>
    </div>
    <div class="calendar-item">
        <div class="calendar-item-head">SAT</div>
        <div class="calendar-item-body">[wpv-view name="schedule-view" cached="off" ts="[ts_day_week day='Saturday']"]</div>
    </div>
    <div class="calendar-item">
        <div class="calendar-item-head">SUN</div>
        <div class="calendar-item-body">[wpv-view name="schedule-view" cached="off" ts="[ts_day_week day='Sunday']"]</div>
    </div>
    <div class="calendar-item">
        <div class="calendar-item-head">MON</div>
        <div class="calendar-item-body">[wpv-view name="schedule-view" cached="off" ts="[ts_day_week day='Monday']"]</div>
    </div>
    <div class="calendar-item">
        <div class="calendar-item-head">TUE</div>
        <div class="calendar-item-body">[wpv-view name="schedule-view" cached="off" ts="[ts_day_week day='Tuesday']"]</div>
    </div>
    <div class="calendar-item">
        <div class="calendar-item-head">WED</div>
        <div class="calendar-item-body">[wpv-view name="schedule-view" cached="off" ts="[ts_day_week day='Wednesday']"]</div>
    </div>
    <div class="calendar-item">
        <div class="calendar-item-head">THU</div>
        <div class="calendar-item-body">[wpv-view name="schedule-view" cached="off" ts="[ts_day_week day='Thursday']"]</div>
    </div>
</div>

But the same days simply repeat over and over again instead of filtering into the correct days of the week. Is this an issue with the function or the view?

#1784777

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Larry,

Based on what I see from the code it is only passing the current day into the view rather than the current Date.

What you want to pass into the view is Today's date rather than the day of the week correct ? What this means that only posts that have Todays actual date will show up rather than the day of the week.

Please let me know if this is what you want.

Thanks,
Shane

#1784969

Well, I don't want to hardcode todays date. If that is what you mean. I want to automatically fill the week by day - IOW put mondays stuff under Monday, tuesdays's stuff under Tuesday etc...

And only show the current week, starting on Thursday (for example).

#1786087

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Larry,

For further clarity, I see in your view that you are using the shortcode parameter to filter by the Day, meaning Monday Tuesday Wednesday etc.

So lets say you want to filter for Wednesday, you will only want posts for Wednesday September 23rd correct and not Wednesday September 16th.

Or is it that you want to display all posts that are on Wednesdays.

Please let me know.
Thanks,
Shane

#1788391

Well, I may want to do both. Provide a week view and a month view- I think that is what you are asking? But for now I'm most concerned with the week (Friday-Thursday).

#1789495

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Larry,

You can only do one at a time, you're not able to do both.

Perhaps i'm not understanding the full picture as to what you are trying to achieve with these date views. Maybe if I know this then I can better able to assist.

Right now I see that you want to display posts for different days using different view.

In this line of code here.


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

It is checking is Today's day is the same as the one that has been entered into the shortcode, then converting this to a timestamp to pass to the view to filter based on Todays day.

This will give all posts that are for Thursday both in the past and future. If you want only future Thursday posts please let me know.
Thanks,
Shane

#1791715

Well, It depends upon when you open the page. If the week is Friday-Thursday but you open it on Wednesday - which Wednesday did you open? The Wednesday before or during? So the point is, I want to be able to build schedules for people and then allow them to view on a F-Tr basis. But those schedules could change over the course of the week. I'm not sure if my explanation helps.

#1793147

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Larry,

I understand what you are trying to achieve.

If the week is Friday-Thursday but you open it on Wednesday - which Wednesday did you open?

If I open the schedule for Wednesday you want to show all the persons rostered for Wednesday, what i'm really confused about is if you want it to be This wednesday or This and Future Wednesdays.

Once I understand this we can move to achieve a fix or a recommendation. I'm assuming that you wouldn't want to display Past Wednesdays only this and future wednesdays.

Thanks,
Shane

#1799085

Actually, I cannot predict what week the user will want to see. But let's make this simple (for the moment).

How can I display the current week, which for us is Friday-Thursday?

Keeping in mind that a user might start their shift on a Thursday and end it on Friday morning.

So if a user is logged in on Thursday at 23:20hrs CST, they would still see the previous weeks schedule, but, at 00:01 Friday the new schedule would show up for the next week.

As far as the dailys go... This seems to me to be easier? If it's 06:00, 15:00, or 23:00 on Thursday or Monday of X date, should be straightforward to show the 'posts' for that day?

I hope that helps.

#1804911

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Larry,

How can I display the current week, which for us is Friday-Thursday?

This will need to be completely custom because PHP defines a week as Sunday-Saturday.

At this point the custom code that is required to achieve the custom week is out of the scope of our support forum. I would recommend contact one of the registered contractors in order to get further assistance with this one.
https://toolset.com/contractors/
Thanks,
Shane

#1807853

My issue is resolved now. Thank you!