php - Order list by specific value within in list item -
i order unordered list specific value inside list items. generate list loop.
my looped list item looks this. value <?php echo $nyslutdatum; ?>
1 wish list ordered (displayed twice because 2 cases of loop conditions)
<li> <div id="kursprogram-kurstillfalle-kurs"> <?php the_title(); ?> </div> <div id="kursprogram-kurstillfalle-ort"> <?php the_sub_field('ort'); ?> </div> <div id="kursprogram-kurstillfalle-datum"> <?php if(get_sub_field('startdatum') != '') { ?> <?php echo $nystartdatum; ?> - <?php echo $nyslutdatum; ?> <?php } else { ?> <?php echo $nyslutdatum; ?> <?php } ?> <?php if(get_sub_field('slutdatum_2') != '') { ?> <br /> <?php echo $nystartdatum_2; ?> - <?php echo $nyslutdatum_2; ?> <?php } ?> </div> <div id="kursprogram-kurstillfalle-notis"> <?php the_sub_field('notis') ?> </div> <div class="clearboth" /> </li>
if understand question correctly, use php function "usort".
the following sort $array highest lowest "sales".
$array = array( array('sales'=> 10, 'views'=> 200), array('sales'=> 3, 'views'=> 100), array('sales'=> 13, 'views'=> 500) ); usort($array,function($a,$b){ if( $a['sales'] == $b['sales'] ){ return 0; } return ($a['sales'] > $b['sales']) ? -1 : 1; });
Comments
Post a Comment