Help Desk

Remove Duplicates from Upcoming Events List

  • Posts: 31 Topics: 11 Answers: 1
    | Permalink

    I have an event that is entered for performances on the same day at different times and I only want it to appear once for that date on the upcoming events list they are not Recurrences but Stand alone events. Is there a way to select distinct post_title from the query so it will appear once no matter how many times it is set to appear over the course of days?
    I thought I could use pre_get_post but I don’t know how to ask for distinct post_title.

    Posts: 18146 Topics: 17 Answers: 973
    | Permalink
    Correct Answer

    Hi Beth,

    I think you’re basically on the right track but perhaps what you need to do is build a list of post IDs that you wish to exclude, and then add those to the query via a post__not_in argument?

    Posts: 31 Topics: 11 Answers: 1
    | Permalink

    Barry

    Are there any examples you could point me to that could help in this process?

    Thanks
    Beth

    Posts: 18146 Topics: 17 Answers: 973
    | Permalink

    Hi Beth,

    I don’t have any specific examples to hand, I’m afraid, and as this is customization territory it’s really something we’d need to leave in your hands (bearing in mind you will need to be responsible for the code’s future maintenance) 🙂

    The Codex itself is probably the best source of information on using post__not_in but essentially you would use it to provide an array of post IDs for exclusion:

    $args = array(
        /* ... other args ... */
        'post__not_in' => array( 10, 20, 30 ),
        /* ...more args ...*/
    );

    Of course you’d probably want to create the array of IDs dynamically and would create a separate query for that.

    Posts: 18146 Topics: 17 Answers: 973
    | Permalink

    Hi!

    It’s been a while so I’m going to go ahead and close this topic.

    • Need help with anything else? Go right ahead and post a new topic, one of the team will be only too happy to help
    • Still need help with this issue and need to re-open it? Again, please simply create a new topic and link to this one to provide the team with some context

    Thanks!