Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function featured_resident_meta(){
- global $post, $wpdb;
- wp_deregister_script('autosave');
- $fres_select = "";
- $fres_val = get_post_meta($post->ID,'fres',true); // get "Page" custom meta data
- echo "<h4>Select a Featured Resident you'd like to display on this page: </h4><select name='fresident'><option value='0'>None</option>";
- $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)
- $featured = $wpdb->get_results($sql,OBJECT);
- foreach($featured as $row):
- if($fres_val){ // has a value, add selected='selected' to that particular row
- $fres_select = ($fres_val == $row->ID)? " selected='selected'" : "";
- }
- echo "<option value='".$row->ID."'$fres_select'>".$row->post_title."</option>";
- endforeach;
- echo "</select>";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement