Navigation überspringen

[Gelöst] Sorting custom group, using a repeating field

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

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Zeitzone des Unterstützers: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Minesh vor 2 years.

Assistiert von: Minesh.

Author
Artikel
#2698454

Tell us what you are trying to do?

I've an elementor pro page versteckter Link which is trying to sort walking tours by date.

The underlying date is from a custom post called Walking Tours (walking-tours) at
versteckter Link
and has a Field Group for Walking Tours at
versteckter Link
which includes a repeating field called Date/Time of Tour (datetime-of-tour).

The walks-grid page shows the date of tours taken from Date/Time of Tour, but I'm trying to work out how to sort this so that the earliest tours appear first (and only from todays date). I've explored various plugins for sorting by custom fields (Advanced Post Queries and Advanced Query Loop), but they don't seem to support Toolset.

My next attempt was to try and use a PHP code snippet (copying from others attempts as I don't really understand PHP):
<?php
add_action( 'elementor/query/walks_post_sort', function( $query ) {
$query->set('post_type', 'walking-tour');
$query->set( 'meta_key', 'datetime-of-tour' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'DESC' );
});

If I activate this snippet then the query fails and the walks-grid page is blank.

I think it is probably failing because datetime-of-tour is a repeating field. Is there a way to sort by the first field in the array of repeating dates?

Is there any documentation that you are following?

I found
https://toolset.com/documentation/customizing-sites-using-php/displaying-repeating-fields-one-kind/#:~:text=Repeating%20fields%20can%20be%20output,cases%20is%20the%20separator%20parameter
and a number of slashdot examples which suggest that this might be the problem, but I don't understand how to apply to me problem.

Any help would be appreciated.

#2698618

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You shared the backend links but I could not access those links until I login to backend addmin.

Can you please send me wp-admin access details and once I review your current setup I will be able to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2698737

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Can you please check now: versteckter Link

With the code snippet you added - I've activated the code snippet and adjusted the code snippet code as given under:
- versteckter Link

add_action( 'elementor/query/walks_post_sort', function( $query ) {
	$query->set('post_type', 'walking-tour');
    $query->set( 'meta_key', 'wpcf-datetime-of-tour' );
    $query->set( 'orderby', 'meta_value_num' );
    $query->set( 'order', 'DESC' );
});

- The change is - Types stores the custom field slug with "wpcf-" prefix. So if you have custom field "name" then the meta key for that will be stored as "wpcf-name".

Can you please confirm it works as expected.