Skip Navigation

[Resolved] Toolset View show duplicate result when I try to group CPT by date field

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

This topic contains 8 replies, has 3 voices.

Last updated by marcoR-9 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1378113
Schermata 2019-11-07 alle 15.35.53.png

I am trying to:
I'm trying to show single "speech of a congress" related to a "congress" post, grouped by date field.
Many "speech" are related to many "congress".
I have created one view for show the date (in bold) and below this, a second view for show the "speech" related to a "congress".

I expected to see:
For one "congress":
29 November 2019
-- Speech 1 (at 1pm)
30 November 2019
-- Speech 2 (at 2pm)
-- Speech 3 (at 3pm)

Instead, I got:
For one "congress":
29 November 2019
-- Speech 1 (at 1pm)
30 November 2019
-- Speech 2 (at 2pm)
-- Speech 3 (at 3pm)
30 November 2019 <<<< duplicate
-- Speech 2 (at 2pm) <<<< duplicate
-- Speech 3 (at 3pm) <<<< duplicate

#1378141

Hi, can you take screenshots of each View so I can see how they are set up in wp-admin? It looks like you have a nested View here. If that is the case, you could move the date into the first row of the nested View using the wpv-item shortcodes.
https://toolset.com/documentation/user-guides/digging-into-view-outputs/#vmeta-wpv-loop-parameters

Then you can use the Post Selection tab in the Fields and Views popup to display information from a related post in the loop. Once I see how your Views are set up I can make a more definite suggestion.

#1378197
Schermata 2019-11-07 alle 17.24.46.png
Schermata 2019-11-07 alle 17.24.37.png
Schermata 2019-11-07 alle 17.24.30.png

I attach three images:
- About loop editor of the first view (title with date and wpv-view shortcode of the second view with the shortcode parameter to passing to second view);
- About loop editor of the second view (in this view, I took the parameter passing by shortcode before);
- About che body of the second view, with the data of the "speech".

Thank you so much

#1378233

In the first View, remove the h5 tag and the date. Move the date into the second View. You can do that by passing the formatted date into a second shortcode attribute like "formatted_date". Then in the second View, use wpv-item blocks to display the date only for the first row:

<wpv-loop>
  [wpv-item index=1]
  <h5>[wpv-attribute name="formatted_date"]</h5>
  [wpv-post-body view_template="loop-item-in-accordion-interventi-del-congresso-by-date"]
  [wpv-item index=other]
  [wpv-post-body view_template="loop-item-in-accordion-interventi-del-congresso-by-date"]
</wpv-loop>

Let me know if this does not make sense and I can try to clarify.

#1378925
Schermata 2019-11-08 alle 15.37.17.png

The problem still remain.
From the first view, I pass the formatted_date argument to the second view:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
		[wpv-view name="accordion-interventi-del-congresso-by-date" startdate="[types field='intervento_data-intervento' output='raw'][/types]" formatted_date="[types field='intervento_data-intervento' style='text' format='j F'][/types]"]
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

In the second view, I wrote this code inside wpv-loop:

[wpv-item index=1]
<h5>[wpv-attribute name="formatted_date"]</h5>
[wpv-post-body view_template="loop-item-in-accordion-interventi-del-congresso-by-date"]
[wpv-item index=other]
[wpv-post-body view_template="loop-item-in-accordion-interventi-del-congresso-by-date"]

but this solution still return me the result in attached file.. three speech repeated three time every day, not grouped 🙁

I need this result:
22 November
-- speech 1
-- speech 2
-- speech 3

23 November
-- speech 4
-- speech 5

Please help!

#1379349

Sorry, I must not understand how the Views are set up. May I log in to your wp-admin area and take a look? I think it help me understand the repetition and provide the correct answer. Please provide login credentials here and let me know where I can see the View on the front-end of your site (provide a URL).

#1380341

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Marco,

Christian is currently on Holiday today but will be back tomorrow to continue this ticket with you.

Thanks,
Shane

#1381113

Okay I see. The problem here is that you have nested two Views that loop over the same posts, so the duplication is expected. I assumed the outer View looped over some other post type, which is not the case here. The only way this nested setup would work is if the outer loop looped over Dates, not Interventi. Dates would have to be a custom post type in some post relationship with Interventi. There is not really an easy way to "group" posts of one post type based on a custom field value, because Views is designed to loop over posts, not fields. Grouping by date here will require custom programming that I'm not able to provide here in the support forums.

#1381757

My issue is resolved now. Thank you! Hi Cristian,
thank you for the answer but I resolve the issues myself.

I have create a loop with custom PHP code and now my goal is achieved.

I have choose this solution also because I have a lot of relationships and I won't create another relationship with another CPT for this goal.. 🙂

Thank you!