Advertisement
Guest User

Get thumbnail with CPT-onomies @ luizhrqas

a guest
Jun 21st, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  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.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement