Bookings View Page - Sorting Order

Hi there Team HP

I refer topic Orders and Bookings display order in which Ihor replied:
…newest orders should appear at the top by default. Also, there’s a known bug with Bookings where past bookings are not moved to the bottom, we’re working on fixing this. By default the nearest bookings should be displayed at the top, regardless of the booking confirmation date.

While scrolling through the code (hivepress-bookings\includes\components\class-booking.php) looking for something else, I stumbled across this piece of code

/**
	 * Sets booking order.
	 *
	 * @param string   $orderby ORDER BY clause.
	 * @param WP_Query $query Query object.
	 * @return string
	 */
	public function set_booking_order( $orderby, $query ) {
		if ( $query->get( 'post_type' ) === 'hp_booking' && $query->get( 'hp_sort' ) ) {
			$orderby = 'post_status ASC, ' . $orderby;
		}

		return $orderby;
	}

Which confirms my previous issue of the oldest bookings always being displayed at the top with the newest at the bottom causing users to need to scroll to the bottom of the page to see the newest bookings. 'post_status ASC, ’

It should be descending if the newest bookings (orders in our use case) are to be at the top, not?

Complements of Google:
Answer: In general terms, Ascending means smallest to largest, 0 to 9, and/or A to Z and Descending means largest to smallest, 9 to 0, and/or Z to A. Ascending order means the smallest or first or earliest in the order will appear at the top of the list: For numbers or amounts, the sort is smallest to largest.

So to have the booking (order) with the greatest number at the top, it does need to be sorted by Descending (DESC), or am I getting this all wrong?

I was playing around with the code a bit in my limited PHP literacy to see what it all does. I change the piece of code I found in the hivepress-bookings\includes\components\class-booking.php file to DESC and noticed it just swaps the bookings status orders (post-status), so cancelled bookings are first followed by completed and then the bookings requiring some action to complete are last, which isn’t what any of us want either, so that’s the wrong piece of code to change to DESC.

I then found another topic on the community How to rearrange, orders, bookings and messages that relates to the same in a way, so I tried Yevhen’s code snippet that he posted in the topic and changed the order to DESC. It then changes the sorting order correctly so the newest bookings are at the top but it removes the booking status groupings, as it then mixes the bookings requiring some action to complete, the completed and cancelled bookings.

So is there any suspected ETA to fixing the bookings orders but still keeping them grouped by status or can someone Team HP side help all us PHP illiterates by combining Yevhen’s code snippet that orders by date but needs to be set to DESC and should run after the code in the hivepress-bookings\includes\components\class-booking.php file that sorts by date but needs to be changed to sort DESC?

That way it will first sort by post_status in ACS order followed by the post date in DESC order, which is what we all seem to be wanting. Users then won’t need to use the pagination to get to the last page and scroll to the bottom of the last page to see their newest/latest bookings, which is not the greatest UX a user would ideally need to see the bookings needing some action to complete first, that I agree with, but the latest/newest bookings at the top of each booking status group.

Yevhen’s code snippet that needs to be changed to DESC

remove_filter( 'posts_orderby', [ hivepress()->booking, 'set_booking_order' ], 10, 2 );

add_filter(
	'posts_orderby', 
	function ( $orderby, $query ) {
		error_log($orderby);
		if ( $query->get( 'post_type' ) === 'hp_booking' && $query->get( 'hp_sort' ) ) {
			$orderby = 'post_date ASC, ' . $orderby;
		}

		return $orderby;
	},
	1000,
	2
);

And the code block in the hivepress-bookings\includes\components\class-booking.php file that needs to stay ASC order

/**
	 * Sets booking order.
	 *
	 * @param string   $orderby ORDER BY clause.
	 * @param WP_Query $query Query object.
	 * @return string
	 */
	public function set_booking_order( $orderby, $query ) {
		if ( $query->get( 'post_type' ) === 'hp_booking' && $query->get( 'hp_sort' ) ) {
			$orderby = 'post_status ASC, ' . $orderby;
		}

		return $orderby;
	}

I also refer topic Bookings order - from newest to oldest as this seems to be an issue dating back a while. And I’m sure if I spend more time filtering through the topics i will find a few more relating to the same.

Hi there Team HP

It has been 29 days since my last comment on this topic and still not a single response from you.

Please advise as to how we could combine the sorting order to include post_status ASC and post date DESC so that the ordering would be unpaid/pending, paid, cancelled and then ordered by date newest to oldest (DESC) as this seems to be a general issue raised by many users in various topics here on the forum.

THANKS!

Still no reply from Team HP… :roll_eyes:

I’m sorry for the late reply, there was a delay in replies to developer-specific topics.

Yes, the mentioned code is related to grouping by status, not newest/oldest (by the booking start date). Please describe the bug if the order within the status groups is incorrect (pending/unpaid bookings should be at the top, then confirmed bookings, and then past/cancelled bookings, within these groups bookings that start earlier should be at the top), once we reproduce it we’ll add it to the bug tracker.

Hi there Ihor

There is no real bug as we understand the current sorting order used.
We were just wondering if there is a way to combine the code snippets to use the default $orderby = 'post_status ASC, ’ . $orderby; and then combining the $orderby = 'post_date ASC, ’ . $orderby; in the same snippet but changing the post_date to DESC so the newest orders within the status grouping would be at the top and not the bottom to prevent users needing to always scroll to get their latest posts/bookings/orders.

Hi,

Thank you for your feedback. Yes, we are aware of the bug when expired bookings (those bookings that were in the past) appear before upcoming bookings. We will try to fix it in future updates, as there is no simple PHP solution.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.