Skip Navigation

[Gelöst] Order by repeating field

This support ticket is created vor 8 Jahre, 3 Monate. 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 13 Antworten, has 2 Stimmen.

Last updated by francoiseR vor 8 Jahre, 3 Monate.

Assigned support staff: Ghennadi.

Captura de pantalla 2014-10-17 01.42.43.png


I created a view with a list of posts ordered by hour. Each post has a repeating field with several dates and times, but in the view only show the time corresponding to a determinate date. For this I have created a shortcode like this:

function fechashoras_func( $atts ) {
	//parametros: eventdates / diaagenda
	$eventdates = $atts["eventdates"];	//fecha en formato "j F - G:i\h\"	
	$fechas_horas_array = explode("|", $eventdates);
	$dia = 0;
	$attdia = $atts["diaagenda"];
	if ($attdia!='')
		$dia = $attdia;
	//obtenemos la fecha a buscar, segun la pagina en la que estemos
	$date_cur_plus = date('Y-m-d', strtotime('+'.$dia.' days'));
	$fecha_buscar = date_i18n("j F", strtotime($date_cur_plus));
	//recorremos las fechas, buscando la de hoy
	$strTextToShow = "";
	$longitud_array = count($fechas_horas_array);

	for($i=0; $i<$longitud_array; $i++)
		$pos = strpos("-".$fechas_horas_array[$i], $fecha_buscar);
		if ($pos == 2 || $pos == 1) {
			$hora = strstr($fechas_horas_array[$i], '-');
			if (strlen($hora)>1)
				$strTextToShow = $strTextToShow.substr($hora,1)."<br>";
	return $strTextToShow;
add_shortcode('fechashoras', 'fechashoras_func');

It works perfectly, but I have detected a problem: the view can´t order the post by the hour correspondig to the current date, it order by the first date that it find in the repeating field. For example, I have a post (titled "Diego el Cigala") with a date-time repeating field: 14/10/2014 - 14:00h and 17/10/2014 - 17:00h and another post (titled "No hay mal que dure 100 años") wiht the date-time repeating field: 16/10/2014 16:45 and 17/10/20014 13:00h. Even thought I ordered the post by this field ascending it display first the first post. I show it in a screenshot.

I hope it can be solved because without this order this list has not sense... but I have not idea how can I do it.

Thanks in advance


Please check this ticket for reference how to order by date, then by time:


Thanks for your reply, Ghennadi. I tried adding this in the beginning of the shortcode:

function fechashoras_func( $atts ) {
	global $WP_Views; 
   if (in_array('posts', (array)$wp_query->get('post_type')) && $WP_Views->current_view ==2466,2588,2107)

But it doesn´t work.


Unfortunately wordpress only allow order by first value of repetitive field. It's very interesting and we are going to create track on for this feature.
For now solutions is: create 2 separate field start date, end date and use it for order posts.


Thanks Ghennadi, but the problem is not with start-end date if not with different start days and hours. For example, a stage play that has different performances:
10th november - 18:00h
11th november - 20:00h
12th november - 20:00
13th november - 18:00h


Can you provide your site credentials, i will check on your site.
Also, provide View name, page where i can see result.


Ok, i see problem, but as i said we can only order by first value of repetitive field.
As solution ( if you not use pagination ) you can use jQuery plugin for sort table values, instead of Views sorting.
Example: tablesorter, hidden link


Thanks Ghennadi,

I tested the tableshorter plugin inserting the code in the view but continues not working. I don't know how deactivate views sorting and i think here is the conflict. I made the test in the view named agenda-home.


Sorry for long reply. Unfortunately i can't load your site. Can you check it?


Ghennadi, the site is working. I could enter without problem.


I've fixed it on your site.
Test: hidden link

What was wrong.

1. Path to JS file. Please download hidden link to your wp-content/themes/THEMENAME/ directory.
2. In header.php change path from hidden link to file on your server.
3. In View, do not use $, instead this use jQuery.

        jQuery("#myTable").tablesorter( {sortList: [[0,0]]} ); 


I put the js document in theme directory, I changed the paht in header.php but I continue having problems combinating views with jquery.

In table head I put:

 <table id="myTable" class="tablesorter">


and I added:

        jQuery("#myTable").tablesorter( {sortList: [[0,0]]} );

in the JS editor
What I'm doing wrong? I'm completly lost

Thanks for your patience!


Fixed, you added wrong path to file.


Thanks Ghennadi, It works perfectly!

Excellent support!