Home Forums Front-end Issues delete double values using php inside an array (wp-querie and ACF)


delete double values using php inside an array (wp-querie and ACF)

  • Hello,

    I’m using advanced custom fields on my website with a select field (type_evenement) with 5 values (val_1, val_2, val_3, val_4, val_5) I’m using also a wp querie on a custom template page to display posts from a category, all posts uses the “select” custom field.

    I’m trying to display all the select values on this page, but only once, so I’m trying to delete the double values, using array_unique, but it’s not working.

    here is the code I wrote to display the values inside the loop, it display all the values, even when double, for example, val_1, val_3, val_4, val_2, val_1, val_1…

    // args
    $today = date("Ymd");
    $args = array (
    'category' => 5,
    'posts_per_page' => -1,
    'meta_key'       => 'debut_date',
    'orderby'       => 'meta_value_num',
    'order'          => 'ASC',
    'meta_query' => array(
    'key'       => 'fin_date',
    'compare'   => '>=',
    'value'     => $today,
    // get results
    $the_query = new WP_Query( $args );
    // The Loop
    <?php if( $the_query->have_posts() ): ?>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            $input = get_field('type_evenement');
    <?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_query(); ?>

    but when using array_unique, nothing is displayed anymore :

    $input = get_field('type_evenement');
    $result = array_unique($input);

    I don’t understand what I’m doing wrong, I know that get_field returns an array, so I guess that array_unique should work no ?

    If someone can help me with this would be nice !

    thanks a lot

Viewing 1 post (of 1 total)

The topic ‘delete double values using php inside an array (wp-querie and ACF)’ is closed to new replies.