ID; // related category posts $catlist = ""; forEach( $cats as $c ) { if( $catlist != "" ) { $catlist .= ","; } $catlist .= $c->cat_ID; } $newQuery = "cat=" . $catlist; query_posts( $newQuery ); $categoryPosts = ""; $count = 0; $items = array(); $topics = array(); if (have_posts()) { while (have_posts()) { if( $count<4 && $currentId!=$post->ID) { $item = new StdClass; $count++; $item->topic = get_post_custom_values("_video_description"); $item->link = get_permalink(); $item->the_post = the_post(); $item->title = the_title( "", "", false ) $items[] = $item; $topics[] = $item->topic; } } # Sort the posts by topic array_multisort($topics, $items); foreach ($items as $item) { $categoryPosts .= '