Skip Navigation

[Resolved] I need to set visible an hour field only if is set different of 00:00

This thread is resolved. Here is a description of the problem and solution.

Problem: Display the time for a custom date field only if the user selects a time.

Solution: Use separate custom inputs for hour and minutes, and include an option for "nothing selected" in each of these. Use conditional logic in your View to determine if values have been selected for these inputs, and display the time based on those selections.

Relevant Documentation: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 7 years, 9 months ago. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by aldoR 7 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#486657

I am trying to: I need to show the hour of an article only if the hour in the date field is set to a specicif hour (ex. 08:45) and hide the hour in the frontend when the hour is not set (ex. 00:00)

So when an article have only a date, I want to show this date in frontend, when an article have the date and the hour, I want to show both

I visited this URL:

I expected to see:

Instead, I got:

#486850

Hello, I'd like to make sure I understand you correctly. You said you want to show the hour on the front end "only if the hour in the date field is set to a specific hour." You also said you want to show the hour on the front end "if is set different of 00:00". These are different rules, and the difference is important, so I need some clarification.

If you look at the date and time inputs, 00:00 is a specific hour, and it is not possible to select an option without a specific hour or a specific minute. In other words, a date with time field will always have a specific hour and will always have a specific minute, even if that is "00".

With that in mind, do you want to test if the hour or minute is something other than 00, or do you want to test if the user has not selected something for hour or minute?

#486952
Schermata 2017-02-08 alle 09.43.53.png
Schermata 2017-02-08 alle 09.44.12.png
Schermata-2017-02-08-alle-09.44.22.jpg

Ok I'm thinking for a workaround.
If I create two separate fields, the first for the date only (I see it's possible to set this) and on other two select field one with hour, one with minutes.

So In view I've added this code: [types field="date" style="text" format="j F Y"][/types] - [types field="hour"][/types]:[types field="minutes"][/types]

In frontend the output correctly shows the minutes only in articles with this fields set, but I see still the " - " and ":" carachters between the hour e minutes fields.

Now I need only a way to put the " - " and ":" in types field hour or minutes for show only when necessary

I hope you understand my needs, If you look this page hidden link
you see the output page, you see the " - " and ":" carachters also in the articles wit non hour, minutes settings.

thanks in advance, Aldo

#487058

Okay, you'll need to use conditional output that tests the value of hour and minutes. If hour AND minutes do not equal an empty string, you will show the content. Here's an example of a conditional that tests custom fields "hour" and "minutes":


[types field="date" style="text" format="j F Y"][/types]
[wpv-conditional if="( $(wpcf-hour) ne '' ) AND ( $(wpcf-minutes) ne '' )"]
 - [types field='hours'][/types]:[types field='minutes'][/types]
[/wpv-conditional]

Some more information on conditional output here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#487414

GREAT!!! now the output in frontend works wery well..
tnx again Christian

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.