Skip Navigation

[Gelöst] Problem displaying repeating fields

This support ticket is created vor 8 Jahre, 4 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 8 Antworten, has 2 Stimmen.

Last updated by francoiseR vor 8 Jahre, 3 Monate.

Assigned support staff: Waqas.

Author
Artikel
#245543
Captura de pantalla 2014-09-20 22.48.45.png

Hello,

I have created a event schedule filtered by one especific day and ordered by hour. The problem is when I have a event in different days in different hours and I used a custom repeating field (created with wp-types). When I display it in the shedule, it show all the hours (from the different days), when I need that it display only the hour from the specific day i have created the filter. I have try also writting as attribute index=0, but it display the first hour of the first day (not the hour from the day is displayed).
I attached a screenshot of the shedule. The problem is in field "hour" in the first column of the table.
Thanks in advance

#245707

Waqas
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

Can you please provide steps to recreate the same thing? So I can recreate it on my localhost and can test for the issue. Please list the plugin names and versions involved in this too.

On the other hand, you can provide access to your website, if possible. I have enabled private details box for this purpose. Please remember to take a backup of your website also.

#245797

Waqas, thanks for reply

I have used: Types v 1.6.3 and Views 1.6.4

The problem is, for example in the view "niños-3" whith the repeating field created with types and named "fecha-y-hora" inside of group of fields "Datos del evento". The view is filtered by day (future day 3 to future day 4) and ordered by the field "fecha-y-hora" showing just the hour, but when I have a repeated field (as in the second event) it display all the hours of diferent days (not only for the especific day betwwen future day 3 and future day 4).

Thanks!

#245974

Waqas
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing the access. I have reviewed the problem in detail.

As a matter of fact, this isn't have to do anything with the query filter, since that runs perfectly fine - that's why you see the events on particular dates.

This has to do with the short code being used in the view, which is responsible for the output of event hours. Since the short code has no logic itself to check for the relevant hour, it will just output the meta value of that field.

At first hand, what I will suggest is, to define your own short code to filter the output of '[types field="fecha-y-hora" style="text" format="G:i"][/types]'.

The idea is, pass the output of above short code to a custom function, and compare around the appropriate logic. Just like you are displaying the title for that page 'Agenda 29/9' and etc. You are evaluating this title based on some future dates, in your template file. So you can use that same logic to filter through custom field values.

Please see http://codex.wordpress.org/Function_Reference/add_shortcode for how to create and use short codes. You will need this to add in your functions.php and will replace the Types field short code with your own, while passing '[types field="fecha-y-hora" style="text" format="G:i"][/types]' as a parameter to your custom short code.

Please let me know if this helps, and if I can help you with anything related.

#247309

Thanks for your reply, Waqas. But I don't know exactly how make this. Could you be a little more specific?

#247372

Waqas
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

Actually, you need to filter the values of repeating field further down, according to the purpose.

For example, a repeating event, has different dates and times. When you query this on a date, it returns that single event. But as a matter of fact, when you access that custom field (holding date/time), it returns it completely, since it is a multiple values field. Further, when you display it using your formatted output short code, it just displays the time - for all available values. For an instance, if you do not format it, you will see "all dates and times" in output. In other words, the output not just displays the time, but the whole value of each repeating element.

This is where you need to filter this. The idea previously mentioned, is about the same thing. Let me try it explain in steps:

1. Define/create a short code: This will be your own custom short code, where you will accept the values of event's date/time field.
2. Filter the values: Your short code function will iterate through the values, and will decide, which one you need to display. For example, which date is being shown, so it will match against each value, for that particular date, and will return the time segment only.
3. Use your short code: Using 'types' field short code instead, you will now use your newly created custom short code. However, you will pass '[types field="fecha-y-hora" style="text" format="G:i"][/types]' as a parameter to your new short code. Since you will use your custom short code in the same view, the view will render the value of types field short code before passing to your short code. And then your short code will be executed. So your short code will work and output as #1 and #2 above.

Tip: As in #3, you may omit the "format" segment of types field short code, so you can have complete values for matching against the required one.

I hope this can take you in the right direction.

If you need further help in coding your short code function and any assistance regarding custom coding, please feel free to contact our certified partners at https://toolset.com/consultant/ .

#247628

Excuse me, Waqas, but I have not idea how can I create a shortcode for override '[types field="fecha-y-hora" style="text" format="G:i"]'

Is something like this?
add_shortcode('types field="fecha-y-hora"', 'types field="fecha-y-hora"_shortcode');
function types field="fecha-y-hora"_shortcode() {
}

Thanks for your patience!

#247708

Waqas
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

Please see http://codex.wordpress.org/Function_Reference/add_shortcode for how to create and use short codes. You will need this to add in your functions.php and will replace the Types field short code with your own, while passing '[types field="fecha-y-hora" style="text" format="G:i"][/types]' as a parameter to your custom short code.

For example:

function footag_func( $atts ) {
     $eventdates = $atts["eventdates"];
.... your further logic here ....
}
add_shortcode('myshortcode', 'footag_func');

While, your short code will be called "myshortcode" and you will use it as:

[myshortcode eventdates="[types field="fecha-y-hora" style="text" format="G:i"][/types]"]

I hope this can help you around creating and using a short code. Please let me know if I can help you with anything related.

#249374

Finally I solved the problem creating a shortcode.

Perhaps is useful to somebody:

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;
	}	

	$date_cur_plus = date('Y-m-d', strtotime('+'.$dia.' days'));
	$fecha_buscar = date_i18n("j F", strtotime($date_cur_plus));
	

	$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');