Skip Navigation

[Résolu] Prevent duplicate posts in veiw

This support ticket is created Il y a 4 années et 2 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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

Supporter timezone: America/Jamaica (GMT-05:00)

Marqué : 

Ce sujet contient 13 réponses, a 2 voix.

Dernière mise à jour par Shane Il y a 4 années et 1 mois.

Assisté par: Shane.

Auteur
Publications
#1788431

Here is the issue, I have views that have multiple conditional statements:

[wpv-conditional if="( $(wpcf-reporting-category) eq 'Scheduled Work' )"]
[wpv-conditional if="( $(wpcf-item-start-date) eq 'TODAY()' )"]
	<tr>
<td  class="red">[types field='vehicle-location'][/types]</td>

<td  class="red">[types field="item-start-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="red">[types field="item-end-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="red">[wpv-post-excerpt]</td>
<td  class="red">[toolset-edit-post-link content_template_slug='edit-kanban-page' target='self']Edit[/toolset-edit-post-link] / [cred-delete-post action='trash' onsuccess='self']Delete[/cred-delete-post] [toolset-edit-post-link content_template_slug='hide-kanban' target='self']Hide[/toolset-edit-post-link]</td>

	</tr>
      [/wpv-conditional]
[wpv-conditional if="( $(wpcf-item-start-date) ne 'TODAY()' )"]
	<tr>
<td  class="yellow">[types field='vehicle-location'][/types]</td>

<td  class="yellow">[types field="item-start-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="yellow">[types field="item-end-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="yellow">[wpv-post-excerpt]</td>
<td  class="yellow">[toolset-edit-post-link content_template_slug='edit-kanban-page' target='self']Edit[/toolset-edit-post-link] / [cred-delete-post action='trash' onsuccess='self']Delete[/cred-delete-post] [toolset-edit-post-link content_template_slug='hide-kanban' target='self']Hide[/toolset-edit-post-link]</td>
      	</tr>
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-items-statuses) ne 'Complete' ) AND ( $(wpcf-item-end-date) gte 'TODAY()' )"]
	<tr>
<td  class="blue">[types field='vehicle-location'][/types]</td>

<td  class="blue">[types field="item-start-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="blue">[types field="item-end-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="blue">[wpv-post-excerpt]</td>
<td  class="blue">[toolset-edit-post-link content_template_slug='edit-kanban-page' target='self']Edit[/toolset-edit-post-link] / [cred-delete-post action='trash' onsuccess='self']Delete[/cred-delete-post] [toolset-edit-post-link content_template_slug='hide-kanban' target='self']Hide[/toolset-edit-post-link]</td>
	</tr>
      [/wpv-conditional]
[wpv-conditional if="( $(wpcf-item-start-date) eq 'TODAY()' ) AND ( $(wpcf-item-end-date) gte 'TODAY()' )"]
	<tr>
<td  class="red">[types field='vehicle-location'][/types]</td>

<td  class="">[types field="item-start-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="">[types field="item-end-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="">[wpv-post-excerpt]</td>
<td  class="">[toolset-edit-post-link content_template_slug='edit-kanban-page' target='self']Edit[/toolset-edit-post-link] / [cred-delete-post action='trash' onsuccess='self']Delete[/cred-delete-post] [toolset-edit-post-link content_template_slug='hide-kanban' target='self']Hide[/toolset-edit-post-link]</td>
	</tr>
      [/wpv-conditional]

[/wpv-conditional]

however, what is happening is that if a post meets more than one criteria it displays more than once. Is there a way to prevent this from happening?

#1790525

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Larry,

Thank you for getting in touch.

If your posts do meet the criteria, they will be displayed multiple times because the post is being checked on each condition each time the view is looped.

The only way to stop this is to ensure that your posts can only meet 1 criteria at a time or combine the conditionals into 1 using an OR or an AND to join them together.

See our documentation below.
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/#connecting-conditions

However I do see that you are joining your conditionals in at least one case, so setting your conditions in a way that the post can only match one criteria will help with the duplicates.

Please let me know if this helps

Thanks,
Shane

#1791719

For some reason I always tend to miss something in those docs. Is there an example that shows how to do what you are mentioning with my issue? It does show an example with the UI but I can't use that, it would break my conditionals. The 'AND' example doesn't fit my issue far as I can tell.

#1793371

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Larry,

Its not so much that the documentation covers this but the problem is that your posts can fit multiple criterias,

One example why you have duplicates is here

[wpv-conditional if="( $(wpcf-item-start-date) eq 'TODAY()' )"]
    <tr>
<td  class="red">[types field='vehicle-location'][/types]</td>
 
<td  class="red">[types field="item-start-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="red">[types field="item-end-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="red">[wpv-post-excerpt]</td>
<td  class="red">[toolset-edit-post-link content_template_slug='edit-kanban-page' target='self']Edit[/toolset-edit-post-link] / [cred-delete-post action='trash' onsuccess='self']Delete[/cred-delete-post] [toolset-edit-post-link content_template_slug='hide-kanban' target='self']Hide[/toolset-edit-post-link]</td>
 
    </tr>
      [/wpv-conditional]
[wpv-conditional if="( $(wpcf-item-start-date) ne 'TODAY()' )"]
    <tr>
<td  class="yellow">[types field='vehicle-location'][/types]</td>
 
<td  class="yellow">[types field="item-start-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="yellow">[types field="item-end-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="yellow">[wpv-post-excerpt]</td>
<td  class="yellow">[toolset-edit-post-link content_template_slug='edit-kanban-page' target='self']Edit[/toolset-edit-post-link] / [cred-delete-post action='trash' onsuccess='self']Delete[/cred-delete-post] [toolset-edit-post-link content_template_slug='hide-kanban' target='self']Hide[/toolset-edit-post-link]</td>
        </tr>

You've added the same exact conditional multiple times in the same post. What you can do to check which conditionals to see which ones are producing the duplicate.

I suspect this one is similar to the view that you are creating to display the information for Today's posts in a case like this you will use this here.

[wpv-conditional if="( $(wpcf-item-start-date) eq 'TODAY()' ) AND ( $(wpcf-item-end-date) gte 'TODAY()' )"]
    <tr>
<td  class="red">[types field='vehicle-location'][/types]</td>
 
<td  class="">[types field="item-start-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="">[types field="item-end-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="">[wpv-post-excerpt]</td>
<td  class="">[toolset-edit-post-link content_template_slug='edit-kanban-page' target='self']Edit[/toolset-edit-post-link] / [cred-delete-post action='trash' onsuccess='self']Delete[/cred-delete-post] [toolset-edit-post-link content_template_slug='hide-kanban' target='self']Hide[/toolset-edit-post-link]</td>
    </tr>
      [/wpv-conditional]

However you will need to add some test text to each of your conditionals to see which conditional is producing the duplicate.
Thanks,
Shane

#1795027

I'll go through and double check.

#1795029

I went through all the views that show up on the home page and I don't see what you see.

#1795811

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Larry,

The conditionals that i'm referring to is the one that you sent in your initial post.
https://toolset.com/forums/topic/prevent-duplicate-posts-in-veiw/#post-1788431

This is what I based my assessment on that the post in the view loop is meeting multiple conditions and since the same fields are being displayed then there will be duplicates.

One example is here.

[wpv-conditional if="( $(wpcf-item-start-date) eq 'TODAY()' )"]
    <tr>
<td  class="red">[types field='vehicle-location'][/types]</td>
  
<td  class="red">[types field="item-start-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="red">[types field="item-end-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="red">[wpv-post-excerpt]</td>
<td  class="red">[toolset-edit-post-link content_template_slug='edit-kanban-page' target='self']Edit[/toolset-edit-post-link] / [cred-delete-post action='trash' onsuccess='self']Delete[/cred-delete-post] [toolset-edit-post-link content_template_slug='hide-kanban' target='self']Hide[/toolset-edit-post-link]</td>
  
    </tr>
      [/wpv-conditional]
[wpv-conditional if="( $(wpcf-item-start-date) ne 'TODAY()' )"]
    <tr>
<td  class="yellow">[types field='vehicle-location'][/types]</td>
  
<td  class="yellow">[types field="item-start-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="yellow">[types field="item-end-date" style='text' format='m/d/y H:i'][/types]</td>
<td  class="yellow">[wpv-post-excerpt]</td>
<td  class="yellow">[toolset-edit-post-link content_template_slug='edit-kanban-page' target='self']Edit[/toolset-edit-post-link] / [cred-delete-post action='trash' onsuccess='self']Delete[/cred-delete-post] [toolset-edit-post-link content_template_slug='hide-kanban' target='self']Hide[/toolset-edit-post-link]</td>
        </tr>

You are checking the start dates against today. So If the post is equal to Today and Not today it will be displayed. Not sure of the goal trying to be achieved here.

If its a for a post that is just to display for Today then you can just check for equal to today only.

Thanks,
Shane

#1796529

But they are two different conditions aren't they. 'eq' or 'ne'.

#1797879

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Larry,

Can you allow me to have admin access to the site so that I can see exactly what is happening ?

I need to see it on a page where the duplicate can be seen clearly. If there is a link for this please sed it as well.

I've enabled the private fields for your next response.

Thanks,
Shane

#1800989

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Larry,

Upon further checks I see that the duplicate is being generate by these conditional here.

[wpv-conditional if="( $(wpcf-item-start-date) ne 'TODAY()' )"]
	<tr>
<td class="yellow">[wpv-post-date format="m/d/y"]</td>

<td class="yellow">[wpv-post-excerpt] Duplicate</td>
<td class="">[toolset-edit-post-link content_template_slug='edit-kanban-page' target='self']<img src="/wp-content/uploads/2020/08/infoc.png" width="20" height="20">[/toolset-edit-post-link] [toolset-edit-post-link content_template_slug='hide-kanban' target='self']Hide[/toolset-edit-post-link]</td>
      	</tr>
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-items-statuses) ne 'Complete' ) AND ( $(wpcf-item-end-date) gte 'TODAY()' )"]
	<tr>
<td class="blue">[wpv-post-date format="m/d/y"]</td>

<td class="blue">[wpv-post-excerpt] Duplicate 2</td>
<td class="">[toolset-edit-post-link content_template_slug='edit-kanban-page' target='self']<img src="/wp-content/uploads/2020/08/infoc.png" width="20" height="20">[/toolset-edit-post-link] [toolset-edit-post-link content_template_slug='hide-kanban' target='self']Hide[/toolset-edit-post-link]</td>
	</tr>
      [/wpv-conditional]

Now this is happening because the posts that produce the duplicates are meeting both conditional statement requirements.

So a review is needed to ensure that your post can only meet 1 of the requirements for each of your conditional shortcode.

For e.g these 2 conditional statement here.
<Code>
[wpv-conditional if="( $(wpcf-item-start-date) ne 'TODAY()' )"]

[wpv-conditional if="( $(wpcf-items-statuses) ne 'Complete' ) AND ( $(wpcf-item-end-date) gte 'TODAY()' )"]
[/php]

As you can see you are checking if the Start date is not equal to today, which can be a day in the past or future and you are checking the end date if it is greater than today.

From this you can see that the start date can also fall into a day that is greater than today and that particular post can also have a status that is not equal to complete, which would cause it to pass both conditional terms.

Thanks,
Shane

#1801231

Alright so here are the parameters:

Red – New information
Yellow – Upcoming task/event
Blue – Unresolved issues (something that hasn't been marked as complete (status field)
Black – Relevant (this is a grey area and I don't know how to deal with it but let's assume it's not in the other 3? but still published)

How would you recommend I change this?

#1801611

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Larry,

The conditional I would suggest changing is this

[wpv-conditional if="( $(wpcf-item-start-date) ne 'TODAY()' )"]

This is too generic as it will display all the posts where the start day is not equal to today. Perhaps taking a look at which posts you want to display, Meaning where the Start date and end date is less that today, or The start date is Equal to today and end date is greater than today.

I'm not sure what posts you want to display with the above condition. Perhaps you can also include a status check, where you want the posts where the start date is not equal to today but you only want the posts with status Complete

It needs to be more specific so that it can target your specific posts, however you must keep in mind that whatever condition you use, you must ensure that it doesn't also allow those same posts to pass this conditional here.
[wpv-conditional if="( $(wpcf-items-statuses) ne 'Complete' ) AND ( $(wpcf-item-end-date) gte 'TODAY()' )"]

If it is a case where the posts will pass , then you will only need this condition on your view.
[wpv-conditional if="( $(wpcf-items-statuses) ne 'Complete' ) AND ( $(wpcf-item-end-date) gte 'TODAY()' )"]

As this will display all the posts where their status's aren't set to complete and their end dates are greater than today.

Thanks,
Shane

#1802445

There has to be a more straightforward way of doing this. For example, can it look at the Post ID and if it already exists, not display it again in the same view? I'm not having any success at this.

#1803233

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Larry,

For example, can it look at the Post ID and if it already exists, not display it again in the same view?

Checking the post ID is possible but checking if the ID already exists i'm not sure what you mean. Are you referring to checking if the post is already displayed? If so then no you are not able to do this.

As stated before the problem is that your posts can meet multiple of your required conditions so your conditional statements needs to be adjusted to be more specific.

From my previous post I mentioned that posts that meet this condition below.

[wpv-conditional if="( $(wpcf-item-start-date) ne 'TODAY()' )"]

They can also meet this condition as well.

[wpv-conditional if="( $(wpcf-items-statuses) ne 'Complete' ) AND ( $(wpcf-item-end-date) gte 'TODAY()' )"]

So the first conditional needs to be more specific so that it can target the exact posts and ensuring that whatever posts that this conditional is displaying does not meet the conditions of any of the other conditional statement.

Thanks,
Shane