Skip Navigation

[Closed] Rotating our coaches on our 'Find a coach' page

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

This topic contains 1 reply, has 2 voices.

Last updated by Christopher Amirian 2 years, 2 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2586619

My client, ADD Coaching, is working with several ADD coaches that clients can contact through our 'Zoek een coach' page (see link below). We would very much like to be able to rotate the coaches every 2 weeks, for example. Now, the first coach on the page (Jasper) is always the one at the top because he was the first coach on the website. But now with 20 twenty coaches, this doesn't seem fair anymore.

I already searched your site and I came across a similar question from somebody regarding rotating his blog posts. The solution was to at a css short code that enabled every new post to be shown first. Is there something similar we do with our coaches, but not set on date? And would it be possible to have it rotate every 2 weeks.

Below is the link to the coach page and how it looks now.
hidden link

Thank you so much for your help!

Best regards,
Marijn Driesen
Virtual Assistant of ADD Coaching

#2586747

Christopher Amirian
Supporter

Languages: English (English )

Hi Marijn,

It is possible to change the order of a view using custom PHP coding.

For that please add a custom PHP code using the method below:

https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

The code that you need to add should be something like this:

add_filter('wpv_filter_query', function ($query, $setting, $view_id) {
    if (in_array($view_id, array(2970))) {
        // Set the date when you want the order to start being reversed
        $start_date = new DateTime('2023-04-04');
        $current_date = new DateTime();

        // Calculate the number of days passed since the start date
        $days_passed = $start_date->diff($current_date)->days;

        // Check if the current week is an even or odd week
        $is_even_week = (int)($days_passed / 14) % 2 === 0;

        if ($is_even_week) {
            $query['orderby'] = array('title' => 'ASC', 'meta_value_num' => 'ASC');
        } else {
            $query['orderby'] = array('title' => 'DESC', 'meta_value_num' => 'DESC');
        }
    }
    return $query;
}, 999, 3);

In this code snippet, we calculate the number of days that have passed since the specified start date, and then we determine if the current week is an even or odd week. If it's an even week, the order will remain the same, otherwise, the order will be reversed.

Make sure to set the $start_date variable to the date when you want the order to start being reversed. In this example, I used '2023-04-04' as the start date, but you can change it according to your needs.

Also, you need to change 2970 in the code to the ID of the view that you are currently using on your website.

Use this method to find the ID of the view that you use:

https://toolset.com/forums/topic/finding-the-view-id

I did not test the code completely, so you might need to do some tweaks to make it work for your scenario.

Thanks.

The topic ‘[Closed] Rotating our coaches on our 'Find a coach' page’ is closed to new replies.