order fields inside CFS() loop wordpress

Here is my code:

$args = array(
        'posts_per_page'      => - 1,
        'post_type' => array('post-type-name'),
        'tax_query' => $taxquery,
        'orderby' => 'meta_value_num',
        'meta_key' => 'date_of_issue',
        'order' => 'DESC',  
);
global $post;
$post_list = get_posts($args);
if ($post_list) {
    foreach ($post_list as $post_item) { ?>
            <?php 
                $fields = CFS()->get('anouncements', $post_item->ID);
                if ( ! empty ( $fields ) ){
                    foreach ($fields as $field_eti) { ?>
                        <div class="item"><?php echo $field_eti['date_of_issue']; ?></div>
               <?php }
                } 
    ?>
        <?php
    }
}

I’m using Custom Field suite plugin. I want to order those fields by this date which is one of the custom fields of that loop ($field_eti['date_of_issue'];). How you see in my $args I added that meta_key and ordered it by custom field value which is date. But ordering isn’t right.

Related posts

1 comment

  1. Try this: I have updated my answer.

    foreach ($post_list as $post_item) { 
    setup_postdata($post_item);  // Set postdata
    ?>
                <?php 
                    $fields = CFS()->get('anouncements');
                    $temp=array();
                    if ( ! empty ( $fields ) ){
                        foreach ($fields as $field_eti) { 
                                   $temp[] = strtotime($field_eti['date_of_issue']);
    ?>
    
                            <div class="item"><?php echo $field_eti['date_of_issue']; ?></div>
                   <?php }
                   $new_field_eti[] = arsort($temp);
                  print_r($new_field_eti);
                    } 
        ?>
            <?php
        }
    

Comments are closed.