Tours and accommodations displayed on destination pages can now be ordered by the sequence set in the backend multiselect fields (tour_to_destination and accommodation_to_destination).
You can enable custom ordering in two ways:
- Checkbox Control - Enable "Custom Order" checkbox in any Query block settings panel
- Automatic Variations - Specific query variations automatically preserve order
- Add a Query Loop block to your page/template
- In the block sidebar settings, find the Tour Operator panel
- Enable the "Custom Order" checkbox
- The query will now preserve the order from connected posts
This works for any query variation - tours, destinations, accommodations, or reviews.
When enabled, the Custom Order checkbox:
- Adds a
custom-orderCSS class to the block - Forces the query to use
orderby=post__in - Preserves the exact order from multiselect fields or
post__inarrays
Example Use Case:
On a destination page showing related tours, the tours will display in the exact order you arrange them in the "Related Tours" multiselect field in the destination editor.
- Edit a destination in the WordPress admin
- Find the "Related Tours" multiselect field
- Select tours in the order you want them to appear
- The order you arrange them in the multiselect box will be preserved on the front-end
Use a Query Loop block with the appropriate variation class name:
- For tours on destination pages:
lsx-tour-related-destination-query - For accommodations on destination pages:
lsx-accommodation-related-destination-query
Example:
<!-- wp:query {"className":"lsx-tour-related-destination-query"} -->These variations automatically enable custom ordering without needing the checkbox.
The ordering system works through these components:
- Custom Field Storage: The
tour_to_destinationfield stores post IDs in the selected order - Query Filter: The
related_connection_query()method retrieves these IDs in order - Orderby Filter: The
enable_post_in_ordering()method enablesorderby=post__infor:- Blocks with the
custom-orderclass - Specific query variations
- Blocks with the
- Result: WordPress queries return posts in the exact order from the custom field
To enable automatic ordering for additional query variations, modify the $ordered_variations array in the enable_post_in_ordering() method:
$ordered_variations = array(
'tour-related-destination',
'accommodation-related-destination',
'your-custom-variation', // Add your variation here
);Controls which query variations use post__in ordering.
Parameters:
$enable(bool): Whether to enable post__in ordering (default: false)$query(array): The query arguments$block(array): The block data
Example:
add_filter( 'lsx_to_query_orderby_post__in', function( $enable, $query, $block ) {
// Custom logic to enable/disable ordering
return $enable;
}, 10, 3 );/includes/classes/blocks/class-query-loop.php- Main query customization logic/src/js/blocks/slider-query.js- Block editor controls (Custom Order checkbox)/includes/metaboxes/config-destination.php- Destination custom fields configuration/includes/metaboxes/config-tour.php- Tour custom fields configuration