Want more features on Pastebin? Sign Up, it's FREE!
Guest

Get thumbnail with CPT-onomies @ luizhrqas

By: a guest on Jun 21st, 2012  |  syntax: PHP  |  size: 1.00 KB  |  views: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     <?php
  2. // i will use the global variable $wpdb
  3.     global $wpdb;
  4. // i get all the terms from taxonomy 'solucoes' with the ID from the loop
  5.     $solucoes = wp_get_object_terms(get_the_ID(), 'solucoes');
  6. // Loop
  7.     foreach($solucoes as $solucao) :
  8.         // I get the thumbnail_id from the term
  9.         $solucaoThumbnailId = $wpdb->get_results('SELECT meta_value FROM wp_postmeta WHERE post_id = "' . $solucao->term_id . '" AND meta_key = "_thumbnail_id"');
  10.         // If my get is TRUE
  11.         if($solucaoThumbnailId) {
  12. // I get the relative URL from the upload inside the wp_postmeta table
  13.             $solucaoThumbnail = $wpdb->get_results('SELECT meta_value FROM wp_postmeta WHERE post_id = "' . $solucaoThumbnailId[0]->meta_value . '"');
  14. // And use this. :)
  15.             echo '<li><a title="' . $solucao->name . '"><img src="' . get_template_directory_uri() . '../../../uploads/' . $solucaoThumbnail[0]->meta_value . '" width="50" height="50" /></a></li>';
  16.         }
  17. // End loop
  18.     endforeach;
  19.     ?>
clone this paste RAW Paste Data