$tags = get_terms( 'fluxus-project-type' ); //gets all the tags $i = 0; //"quick fix for the current thingy, where there's a hidden project" foreach($tags as $tag) : //for loop that goes through all the project type tags $i++; //continuation of the "quick" fix the_post(); $project = new PortfolioProject( get_the_ID() ); $test = $project->all(); //gets all the projects as an array for($k = 0; $k < sizeof($test);$k++) //loops through the array { $test2 = $test[$k]->get_tags(); //gets the tag from the current project we're on if(sizeof($test2) == 1 && $test2[0]->term_id == $tag->term_id) //checks if the project we're on, fits the $tag { $featured = $test[$k]->get_featured_media(); //sets the $featured as the project image from the project we're on break; //breaks the for loop, since we've gotten what we need }else if(sizeof($test2) > 1) //checks if the project we're on has more than 1 project type associated with it { for($z = 0; $z < sizeof($test2); $z++) //loops through the current projects "many" project types { if($test2[$z]->term_id == $tag->term_id) //if the project type fits the $tag, we set the featured image. { $featured = $test[$k]->get_featured_media(); break; //again, breaks.. } } } } if ( ! $featured ) continue; // We have no media on this project, nothing to show. $image = $featured->is_image() ? $featured->get_image_data( 'fluxus-thumbnail' ) : $image = $featured->get_video_thumbnail( 'fluxus-thumbnail' ); if ( $image ) { $image = $image['src']; } else { $image = array( 'src' => get_template_directory_uri() . '/images/no-portfolio-thumbnail.png' ); }