Problem Displaying Custom Values
-
Hello Everyone.I have 2 custom fields Country Name and Website Url in custom post_type ..i actually need to assign url to thumb image which i have done ,have total 10 posts in that ..3 with the same country name but different url’s ,again 3 with the same country name but different url’s and rest all with different countries..i need to display post like this..
Country Name Available Retailers
US ThumbLink1 ThumbLink2 ThumbLink3
UK ThumbLink4 ThumbLink5 ThumbLink6Here is my code which i am trying to do so..but when i add a posts with US field value twice it display it twice in country name which i do not want…
$pfportfolio = new WP_Query( array('post_type' => 'references','posts_per_page' => -1));?> <table cellpadding="1" cellspacing="1" align="center" width="250px" border="1"><tr><td>Country Name</td> <td>Available Retailers</td> </tr> <?php $data=''; while ( $pfportfolio->have_posts() ) : $pfportfolio->the_post(); echo '<tr>'; ?> <td> <?php $country = get_post_meta(get_the_ID(),'country-name'); for($i=0;$i<count($country);$i++) { if ( $country_name != $country[$i]){ echo $country[$i]; } $country_name = $country[$i]; $querystr = "SELECT wposts.* FROM ".$wpdb->posts." AS wposts INNER JOIN ".$wpdb->postmeta." AS wpostmeta ON wpostmeta.post_id = wposts.ID AND wpostmeta.meta_key = 'country-name' AND wpostmeta.meta_value = '".$country_name."' AND wposts.ID=" .get_the_ID(); $values = $wpdb->get_results($querystr); echo '</td><td>'; foreach($values as $value) { $query_thumb = "SELECT meta. * , p.guid FROM ".$wpdb->postmeta." meta INNER JOIN ".$wpdb->posts." p ON p.ID = meta.meta_value WHERE p.ID = meta.meta_value AND meta.post_id ='".$value->ID."' AND meta.<code>meta_key</code> = '_thumbnail_id'"; $guid = $wpdb->get_results($query_thumb); //print_r($guid); $url = get_post_meta($value->ID,'website-url'); //for($i=0;$i<count($url);$i++) //print_r($value); //echo $value->post_title; echo '<a href="'.$url[0].'" rel="abc">'; //echo the_post_thumbnail(); echo ' <img alt="debian_logo" class="attachment-post-thumbnail wp-post-image" src="'.$guid[0]->guid.'">'; echo '</a>'; //echo $u; //echo $value->ID; } }?> </td><?php endwhile; echo '</tr>'; ?> </table>
Any Suggestion is welcomed
- The topic ‘Problem Displaying Custom Values’ is closed to new replies.