• Hello everybody,

    I’m so close to solving this but I’m stuck in the follow. Our website displays the 3 most upcoming events in our front page. By default the theme has no ability to show a featured event rather it only orders events by date. I’ve been able to add the ability to feature 1 event on the left while leaving 2 slots for upcoming events on the right. My problem now is when the featured event is soon it displays on the right side showing as well resulting on two identical events (the featured and the upcoming). I want to be able to remove any duplicates. I’ve tried other tutorials using array_unique but I’ve had no luck.

    Here is another thing that I would like to do as well. Right now my site will display 1 featured event to the left and 2 upcoming to right equaling in 3. The problem is that when I don’t have any featured events the front page only displays 2 events making the site look off balance. I would like to some how say that if there is no featured event display 3 upcoming events instead of 2.

    Thank you again for your help.

    backticks
    // Categories events

    $args1 = array(
    ‘post_type’ => ‘dd_events’,
    ‘posts_per_page’ => 1,
    ‘post_status’ => array( ‘future’ ),
    ‘order’ => ‘ASC’,
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘featured’,
    ‘value’ => ‘yes’,
    )
    )

    );

    $args2 = array(

    ‘post_type’ => ‘dd_events’,
    ‘posts_per_page’ => 2,

    ‘post_status’ => array( ‘future’ ),
    ‘order’ => ‘ASC’,

    );

    $query1 = new WP_Query($args1);
    $query2 = new WP_Query($args2);
    $query3 = new WP_Query($dd_number);

    $dd_query = new WP_Query ();

    $dd_query->posts = array_merge( $query1->posts, $query2->posts );

    //populate post_count count for the loop to work correctly
    $dd_query->post_count = $query1->post_count + $query2->post_count;

    if ( $dd_query->have_posts() ) : $start_at = true; $count = 0; ?>

    <div class=”events-no-cal-wrapper home-section <?php echo $wrapper_class; ?>”>
    backticks

The topic ‘Display array with no duplicates’ is closed to new replies.