Advertisement
r0bbiem

WP Edit post page with WP_Query problem

Mar 10th, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1. // --> In functions.php
  2.  
  3. // Build Arrays
  4.  
  5. $artistList =  array();
  6. $genresList = array();
  7.  
  8. add_action('init', 'getArtists');
  9. add_action('init', 'getGenres');
  10.  
  11. function getArtists()
  12. {
  13.     global $artistList;
  14.     $loop = new WP_Query( array( 'post_type' => 'artists' ) );
  15.     while ( $loop->have_posts() ) : $loop->the_post();
  16.     array_push($artistList, get_the_title());
  17.     endwhile;
  18. }
  19.  
  20.  
  21. function getGenres()
  22. {
  23.     global $genresList;
  24.     $terms = get_terms('genres', array( 'hide_empty' => 0));
  25.     $count = count($terms);
  26.     if ( $count > 0 ){
  27.         foreach ( $terms as $term ) {
  28.             array_push($genresList, $term->name);
  29.         }
  30.     }
  31. }
  32.  
  33. // --> In custom plugin file
  34.  
  35. add_action( 'add_meta_boxes', 'tracks_meta_box_add' );
  36. add_action( 'save_post', 'tracks_meta_box_save' );
  37.  
  38. function tracks_meta_box_add()  
  39. {
  40.     add_meta_box( 'tracks-artist-mb', 'Artist', 'initTracksArtistMb', 'tracks', 'normal', 'high' );
  41.     add_meta_box( 'tracks-genre-mb', 'Genre', 'initTracksGenreMb', 'tracks', 'normal', 'high' );
  42.     add_meta_box( 'tracks-position-mb', 'Chart Position', 'initTracksPositionMb', 'tracks', 'normal', 'high' );  
  43.     add_meta_box( 'tracks-vimeoLink-mb', 'Vimeo Link', 'initTracksVimeoMb', 'tracks', 'normal', 'high' );
  44.     add_meta_box( 'tracks-youtubeLink-mb', 'YouTube Link', 'initTracksYoutubeMb', 'tracks', 'normal', 'high' );
  45.      
  46. }
  47.  
  48. function initTracksArtistMb($post)
  49. {
  50.     global $artistList;
  51.     $values = get_post_custom( $post->ID );  
  52.     $selected = isset( $values['track_artist'] ) ? esc_attr( $values['track_artist'][0] ) : '';  
  53.     //wp_nonce_field( 'artist_nonce', 'meta_box_nonce' );
  54.    
  55.     echo '<p><em>&bull; Choose an existing artist</em></p>';
  56.     echo '<label for="track_artist"></label>';
  57.     echo '<select name="track_artist" id="track_artist">';
  58.     echo '<option>Select an Artist...</option>';
  59.     foreach ($artistList as $artist)
  60.     {
  61.         ?>
  62.         <option value="<?php echo $artist; ?>" <?php selected($selected, $artist); ?>><?php echo $artist; ?></option>
  63.         <?php
  64.     }
  65.     echo '</select>';
  66.     echo '<p><em>&bull; Or add a new artist</em></p>';
  67.     echo '<p><a href="#">Add new Artist</a></p>';
  68. }
  69.  
  70. function initTracksGenreMb($post)
  71. {
  72.     //wp_nonce_field( 'genre_nonce', 'meta_box_nonce' );
  73.     global $genresList;
  74.     $values = get_post_custom( $post->ID );
  75.     $check = isset( $values['track_genres'] ) ? esc_attr( $values['track_genres'] ) : '';
  76.     $count = sizeof($genresList);
  77.     echo '<p><em>&bull; Choose from existing genres</em></p>';
  78.     echo '<div id="genre-check-list" class="sl-node">';
  79.     for($i=0; $i<$count; $i++)
  80.     {
  81.         echo '<div class="genre-check-item sl-node">';
  82.         echo '<input type="checkbox" id="track_genres" name="track_genres" ', checked( $check, 'on' ), '/>';
  83.         echo '<label for="', $genresList[$i], '">', $genresList[$i], '</label>';
  84.         echo '</div>';
  85.     }
  86.     echo '</div>';
  87.     echo '<p><em>&bull; Or add a new genre</em></p>';
  88.     echo '<p><a href="#">Add New Genre</a></p>';
  89. }
  90.  
  91. function tracks_meta_box_save($post_id)
  92. {
  93.     // Save the data
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement