Skip Navigation

[Resolved] How to show all dates, inclusive post title plus some fields

This support ticket is created 3 years, 6 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.

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)

Author
Posts
#2038765

Tell us what you are trying to do? We are having "products" as tours and each tour is having dates, when they starting.

Showing those dates in a tour self is okay and I can do this.

Now I like to create a page where I show all dates inclusive it's post title and some custom fields. Similar to this (I will not create a table, due to the responsive issues).

hidden link

Sure I just could create a page with manually filling the dates... But as we have the tour dates in already, I like to have it dynamically.

The order should be per dates. Would it be a good idea to create a view?

Is there any documentation that you are following? I didn't found a document for this.

Is there a similar example that we can see? hidden link

What is the link to your site? hidden link

#2039793

The order should be per dates. Would it be a good idea to create a view?
Yes, I think a View would be appropriate here. You can create a View using the View block in the Page editor. Create a View of the Product post type, then drag in blocks to display information about each Product post. For example, you can drag in a Single Field block and use the dynamic content feature to display the custom date field.

When you select the top-level View block, you will see an "Ordering" panel appear in the sidebar. This is where you can choose the custom date field to sort the results by date field.

Let me know if you need additional information about this. We have documentation for creating Views available here:
https://toolset.com/course-lesson/creating-a-view/

#2040259

Dear Christian Cox

thank you for this answer. We are using the "calssic" view as we don't use Gutenberg blocks, but I assume it will be the same.

One more question - is it possible to split up results into groups - meaning - we have dates in the year 2021, then 2022 etc?

Splitting up into the years - is this possible?

Regards

#2040273

Dear Christian Cox

What we are having now is this: hidden link

But we would like to see each row as followed:

09/01/2021 | 11 | Bangkok to Khao Lak coastal ride
18/01/2021 | 5 | Phuket – Phang Nga Explorer
15/01/2021 | 5 | Phuket – Phang Nga Explorer
17/02/2021 | 5 | Phuket – Phang Nga Explorer
20/02/2021 | 11 | Bangkok to Khao Lak coastal ride

etc

#2040321

Dear Christian Cox

I am thinking - if it could be easier to achieve - if we have a new custom type, like Tour Dates (Tour Date) - with 2 fields (a date field with multiple entries) plus a post reference to the "products".

And then creating based on this the view.

Regards

#2040943

thank you for this answer. We are using the "calssic" view as we don't use Gutenberg blocks, but I assume it will be the same.
Yes, you'll still need to create a View, whether you use the legacy View editor or the Blocks editor.

One more question - is it possible to split up results into groups - meaning - we have dates in the year 2021, then 2022 etc?
It might be easier to create multiple Views with date filters, so that the dates are between Jan 01 2021 and Dec 31 2021, then another View with a filter between Jan 01 2022 and Dec 31 2022, etc.

I am thinking - if it could be easier to achieve - if we have a new custom type, like Tour Dates (Tour Date) - with 2 fields (a date field with multiple entries) plus a post reference to the "products".
Views are designed to loop over posts, not custom field values. So if you have multiple dates in a single post, it will be more difficult to loop over those dates in a View than if you have multiple posts with a single date field. Maybe it would be helpful for me to log in and see how your data is set up? If you need assistance feel free to provide login credentials in the private reply fields here and I can take a closer look.

#2041375

Okay I was able to get the duration value to display in each row of the "table" by adding index='0' to the Types field shortcode in the Loop Item Template like so:

[wpv-for-each field="wpcf-start-tour-date"]
<div class="rTableRow">
<div class="rTableCell tourstart">[types field='start-tour-date' style='text' format='d. F Y' separator=', '][/types]</div>
<div class="rTableCell tourduration">[types field='tour-days' index='0'][/types]</div>
  <div class="rTableCell tour"><a href="[wpv-post-url]">[wpv-post-title]</a></div>
</div>
[/wpv-for-each]

However, this does not address the date order issue. I'm not exactly clear about the desired order of the results. Is this sort order what you want to achieve, or some other order? Please explain exactly how you want to sort the dates in this list:
09. January 2021 | 11 | Bangkok to Khao Lak coastal ride
15. January 2021 | 5 | Phuket – Phang Nga Explorer
18. January 2021 | 5 | Phuket – Phang Nga Explorer
17. February 2021 | 5 | Phuket – Phang Nga Explorer
20. February 2021 | 11 | Bangkok to Khao Lak coastal ride
25. February 2021 | 5 | Phuket – Phang Nga Explorer
06. March 2021 | 11 | Krabi to Krabi – Pearls of Southern Thailand
31. March 2021 | 5 | Phuket – Phang Nga Explorer
03. April 2021 | 11 | Bangkok to Khao Lak coastal ride
15. May 2021 | 11 | Bangkok to Khao Lak coastal ride
30. June 2021 | 5 | Phuket – Phang Nga Explorer
17. July 2021 | 11 | Bangkok to Khao Lak coastal ride
23. October 2021 | 11 | Magical Mekong River
06. November 2021 | 11 | Bangkok to Khao Lak coastal ride
20. November 2021 | 11 | Krabi to Krabi – Pearls of Southern Thailand
12. December 2021 | 11 | Bangkok to Khao Lak coastal ride

#2041729

Dear Christian Cox

Well, we just like to show our customers when a next cycling tour is. I also can think about having some custom coding... if needed.

Regards

#2042477

Well, we just like to show our customers when a next cycling tour is. I also can think about having some custom coding... if needed.
Okay but I'm not sure what this means, and what you need from me. The next cycling tour is included in the results shown now in the View, so is the problem solved? If not, please explain what you want to change in the current results. Do you want to hide the rows with dates older than "today"? Do you want to change the order in which these results are displayed? How exactly should the order change - should the rows be sorted by date, or grouped by tour and sorted secondarily by date? I'm not quite sure what you want to accomplish now based on the information you have shared so far.

We offer the following APIs you may find useful for custom code solutions, if you are interested in that approach:
Get the results of a View in PHP:
https://toolset.com/documentation/programmer-reference/views-api/#get_view_query_results

Get the values of a repeating date field in PHP (click "More Info" to see code examples):
https://toolset.com/documentation/customizing-sites-using-php/functions/#date

If you want to achieve something specific, please explain in more detail and I can give more guidance.

#2043335

Dear Christian Cox

It isn't solved yet, as it is not ordered per date. It seems as it is ordered per tour first, and then per date.

I like to have it ordered per date.

Regards

#2045187

Okay thank you for the additional information. I can think of two ways to accomplish the display you have described, filtered by date:
1. Instead of storing the Tour Start Date information in a date field that supports multiple values, add a new repeatable field group (RFG) to the Cycling Tour field group and place a date field in this RFG. When you edit a Product (Tour), add a new row to the RFG for each tour start date.

Instead of a View of Products (Tours) to display these tours and dates, create a View of the RFG. Now it is no longer necessary to use a wpv-for-each shortcode, because each date field only contains a single value. In the loop of the RFG View, insert the date custom field value using a Types field shortcode. To display information about the parent post, like the parent post title and the parent post duration field, use the item attribute with @relationship-slug.role syntax:

[wpv-post-link item="@rfg-slug.parent"]
[types field="tour-days" item="@rfg-slug.parent"][/types]

Replace rfg-slug with the slug of the new dates RFG.

This solution requires no additional custom code, but it has limitations. The main limitation is that a View of RFGs cannot be filtered or sorted by fields in the parent post type, and a View of the parent post type cannot be filtered or sorted by fields in the RFG. This might be a problem if you plan to add Query Filters to the results here based on fields in the Product (Tour) post. For example, if you plan to filter the results by price, accommodation, fly out of, etc., this will require custom programming.

If you are already displaying the Tour Start Date fields in a View, template or other location on the site, you'll need to update that code to display the new date field. Usually a View is required to display information like this from an RFG.

2. Create a custom solution using our PHP APIs. I can help you find the relevant documentation for these APIs, I can share code examples, and I can help troubleshoot your code if you run into problems. However, I cannot create a copy + paste custom solution for you per our support policy: https://toolset.com/toolset-support-policy/
This solution is the most flexible, but it requires developer-level understanding of PHP, WordPress, and Toolset APIs.

Let me know if you have questions about these two options, or let me know how you would like to proceed.

#2045929

Dear Christian Cox

Thank You for this answer. Right now, we like to keep as it is - respectively not like to change too much. Instead - we like to show on a different way the tour dates: hidden link

<h2>[wpv-post-title]</h2>
<p>Tour Duration: [types field="tour-days"][/types] days / [types field='number-of-tour-nights' format='FIELD_VALUE'][/types] nights</p>
[wpv-conditional if="( $(wpcf-start-tour-date) ne '' )"]
<h3>Tour dates:</h3>
[wpv-for-each field="wpcf-start-tour-date"]
<p class="mytourdates">[types field="start-tour-date"][/types]</p>
[/wpv-for-each]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-start-tour-date) eq '' )"]
<p class="notourdates">We don't have any tours at the moment</p>
[/wpv-conditional]

What I need to know is, how can I sort the dates? I can't choose the dates in the "secondary sorting".

Regards,

#2046243

What I need to know is, how can I sort the dates? I can't choose the dates in the "secondary sorting".
The problem is there is no easy way to sort date fields that support multiple values like this in a View. You would need to use custom PHP code to get all the posts and all the custom field values, then sort them manually using PHP sorting functions, and then loop over the results using your own PHP custom code. As I said before, Views is designed to loop and sort posts, not loop and sort custom fields that support multiple values.

How to get the results of a View in PHP:
https://toolset.com/documentation/programmer-reference/views-api/#get_view_query_results

How to get the values of a repeating date field in PHP (click "More Info" to see code examples):
https://toolset.com/documentation/customizing-sites-using-php/functions/#date