Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2011
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. function featured_resident_meta(){
  2.     global $post, $wpdb;
  3.  
  4.     wp_deregister_script('autosave');
  5.     $fres_select = "";
  6.     $fres_val = get_post_meta($post->ID,'fres',true); // get "Page" custom meta data
  7.    
  8.     echo "<h4>Select a Featured Resident you'd like to display on this page: </h4><select name='fresident'><option value='0'>None</option>";
  9.     $sql = "SELECT p.ID, p.post_title, r.object_id FROM ".$wpdb->prefix."posts p INNER JOIN (SELECT object_id FROM ".$wpdb->prefix."term_relationships WHERE term_taxonomy_id = 1) r ON r.object_id = p.ID  ";  // custom sql to pull necessary data (ID and title of the posts in the category)
  10.     $featured = $wpdb->get_results($sql,OBJECT);
  11.    
  12.     foreach($featured as $row):
  13.         if($fres_val){ // has a value, add selected='selected' to that particular row
  14.             $fres_select = ($fres_val == $row->ID)? " selected='selected'" : "";
  15.         }
  16.         echo "<option value='".$row->ID."'$fres_select'>".$row->post_title."</option>";
  17.     endforeach;
  18.     echo "</select>";
  19.    
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement