Advertisement
estreet

Word Press Custom Meta Drop Box

Oct 20th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. <?php
  2. // Meta is saving correctly but cannot figure out how to get saved meta chosen as selected
  3.  
  4. // Contributors Circle Meta Box Layout
  5. function contributors_circle_meta_box( $object, $box ) {
  6.  
  7. // $get_categories pulls all regular post categories
  8. $get_categories = get_terms('category');
  9.  
  10. // $my_query pulls all current employee names (employees are in as a custom post employees)
  11. $my_query = new WP_Query('post_type=employees');
  12.  
  13.  
  14. $published_contributors = new WP_Query( array ( 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'contributors_circle' ) );
  15. $selected='';
  16.  
  17. // this foreach displays each category name with a dropbox with a choice of all current //employees, it is displaying correctly, except that it does not have the correct employee
  18. // name selected when the edit page loads.  I have printed the_meta() on the page, the correct // data is showing but cant pull it up as selected.
  19.  
  20. foreach ($get_categories as $term){ ?>
  21.     <div id = "outerwrap">
  22.     <div id = "innerwrap">
  23.     <p style="font-weight:bold;">
  24.     <?php echo $term->name;?>
  25.     </p>
  26.     </div>
  27.     <select name="contributor-<?php echo $term->slug?>">
  28.     <option id="no-contributions" value="No Contributions Received">No Contributions Received</option>
  29.     <?php
  30.  
  31. // This while loop loads the names of all the employees which are a custom                  //post type, the title of the custom post type is the name of the employees
  32.  
  33.         while($my_query->have_posts()) : $my_query->the_post();
  34.         $contributor_meta = get_post_meta($current_post->ID, 'contributor-' . $term->slug, TRUE);
  35.         // If the name of the employee that is being pulled (title of the custom post              
  36.         // type employees) equals the $contributor_meta (also the employees name this
  37.         // is saving correctly but currently the if statement is passing as TRUE for
  38.         // all employees passing through
  39.        
  40.         if (the_title() == $contributor_meta){
  41.             $selected=' selected="selected"';
  42.             }
  43.             else {$selected='';}
  44.             ?>
  45.         <option <?php echo $selected?> id="contributor-<?php echo $term->slug?>" value="<?php the_title() ?>"><?php the_title(); ?></option>
  46.     </div>
  47.     <?php
  48.     endwhile;
  49.     ?>
  50.     </select>
  51.     <?php
  52. }
  53. wp_reset_Query();
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement