Advertisement
Guest User

Untitled

a guest
Apr 17th, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.22 KB | None | 0 0
  1. $collection_rows = get_field('collection_profiles');
  2.                 if ($collection_rows) {
  3.  
  4.                     function cmp($a, $b) {
  5.                         if ($a->collection_profile_note == $b->collection_profile_note) {
  6.                             return 0;
  7.                         } else {
  8.                             return $a->collection_profile_note < $b->collection_profile_note ? 1 : -1;
  9.                         }
  10.                     }
  11.                     uasort($collection_rows, 'cmp');
  12.                     print_r($collection_rows);
  13.  
  14.                     echo '<h2>'.__('Profiles in Collection','roots').'</h2>';
  15.                     echo '<ul>';
  16.  
  17.                     foreach($collection_rows as $collection_row) {
  18.                         // Extract single post value
  19.                         $collection_profile_field = $collection_row['collection_profile'];
  20.                         $collection_profile_page = isset($collection_profile_field[0]) ? $collection_profile_field[0]->ID : NULL;
  21.                         ?>
  22.                         <li><a href="<?php echo get_permalink($collection_profile_page); ?>"><?php echo get_the_title($collection_profile_page); ?></a> <?php echo $collection_row['collection_profile_note']; ?></li>
  23.                     <?php }
  24.                     echo '</ul>';
  25.                 }
  26.  
  27.  
  28.  
  29.  
  30. // The above outputs:
  31.  
  32. Array
  33. (
  34.     [2] => Array
  35.         (
  36.             [collection_profile] => Array
  37.                 (
  38.                     [0] => stdClass Object
  39.                         (
  40.                             [ID] => 207
  41.                             [post_author] => 1
  42.                             [post_date] => 2012-02-23 13:35:55
  43.                             [post_date_gmt] => 2012-02-23 19:35:55
  44.                             [post_content] =>
  45.                             [post_title] => Casing Test Profile
  46.                             [post_excerpt] =>
  47.                             [post_status] => publish
  48.                             [comment_status] => closed
  49.                             [ping_status] => closed
  50.                             [post_password] =>
  51.                             [post_name] => casing-test-profile
  52.                             [to_ping] =>
  53.                             [pinged] =>
  54.                             [post_modified] => 2012-02-23 13:35:55
  55.                             [post_modified_gmt] => 2012-02-23 19:35:55
  56.                             [post_content_filtered] =>
  57.                             [post_parent] => 0
  58.                             [guid] => http://domain.com/?post_type=moulding_profiles&#038;p=207
  59.                             [menu_order] => 0
  60.                             [post_type] => moulding_profiles
  61.                             [post_mime_type] =>
  62.                             [comment_count] => 0
  63.                             [ancestors] => Array
  64.                                 (
  65.                                 )
  66.  
  67.                             [filter] => raw
  68.                         )
  69.  
  70.                 )
  71.  
  72.             [collection_profile_note] => 2
  73.         )
  74.  
  75.     [1] => Array
  76.         (
  77.             [collection_profile] => Array
  78.                 (
  79.                     [0] => stdClass Object
  80.                         (
  81.                             [ID] => 188
  82.                             [post_author] => 1
  83.                             [post_date] => 2012-02-17 15:24:24
  84.                             [post_date_gmt] => 2012-02-17 21:24:24
  85.                             [post_content] =>
  86.                             [post_title] => Test Profile
  87.                             [post_excerpt] =>
  88.                             [post_status] => publish
  89.                             [comment_status] => closed
  90.                             [ping_status] => closed
  91.                             [post_password] =>
  92.                             [post_name] => test-profile
  93.                             [to_ping] =>
  94.                             [pinged] =>
  95.                             [post_modified] => 2012-02-28 14:13:32
  96.                             [post_modified_gmt] => 2012-02-28 20:13:32
  97.                             [post_content_filtered] =>
  98.                             [post_parent] => 0
  99.                             [guid] => http://domain.com/?post_type=moulding_profiles&#038;p=188
  100.                             [menu_order] => 0
  101.                             [post_type] => moulding_profiles
  102.                             [post_mime_type] =>
  103.                             [comment_count] => 0
  104.                             [ancestors] => Array
  105.                                 (
  106.                                 )
  107.  
  108.                             [filter] => raw
  109.                         )
  110.  
  111.                 )
  112.  
  113.             [collection_profile_note] => 3
  114.         )
  115.  
  116.     [0] => Array
  117.         (
  118.             [collection_profile] => Array
  119.                 (
  120.                     [0] => stdClass Object
  121.                         (
  122.                             [ID] => 273
  123.                             [post_author] => 1
  124.                             [post_date] => 2012-03-26 07:53:45
  125.                             [post_date_gmt] => 2012-03-26 13:53:45
  126.                             [post_content] =>
  127.                             [post_title] => Profile 1
  128.                             [post_excerpt] =>
  129.                             [post_status] => publish
  130.                             [comment_status] => closed
  131.                             [ping_status] => closed
  132.                             [post_password] =>
  133.                             [post_name] => profile-1
  134.                             [to_ping] =>
  135.                             [pinged] =>
  136.                             [post_modified] => 2012-04-12 08:07:35
  137.                             [post_modified_gmt] => 2012-04-12 14:07:35
  138.                             [post_content_filtered] =>
  139.                             [post_parent] => 0
  140.                             [guid] => http://domain.com/?post_type=moulding_profiles&#038;p=273
  141.                             [menu_order] => 0
  142.                             [post_type] => moulding_profiles
  143.                             [post_mime_type] =>
  144.                             [comment_count] => 0
  145.                             [ancestors] => Array
  146.                                 (
  147.                                 )
  148.  
  149.                             [filter] => raw
  150.                         )
  151.  
  152.                 )
  153.  
  154.             [collection_profile_note] => 1
  155.         )
  156.  
  157. )
  158.  
  159. so the actual print_r() is not outputting the arrays in order and then the foreach() statement is outputting:
  160.  
  161.     2
  162.     3
  163.     1
  164.  
  165. again - not in order.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement