Advertisement
Guest User

WP_Query not returning custom fields

a guest
Nov 10th, 2011
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2.     $keys = array('Show Date','Birth Year','Origin');
  3.  
  4.     echo '<table>';
  5.     echo '<tr><th>Title</th>';
  6.     foreach( $keys as $key ) {
  7.         echo '<th>' . $key . '<th>';
  8.     }
  9.     echo '</tr>';
  10.  
  11.     $myquery = new WP_Query( 'post_type=post' );
  12.     if( $myquery->have_posts() ) : while( $myquery->have_posts() ) : $myquery->the_post();
  13.  
  14.         $title = get_the_title();
  15.         echo '<tr><td>' . $title . '</td>';
  16.  
  17.         $values = array();
  18.         foreach( $keys as $key ) {
  19.             $values[] = get_post_meta($post->ID, $key, true);
  20.         }
  21.         foreach( $values as $value ) {
  22.             echo '<td>';
  23.             echo $value;
  24.             echo '</td>';
  25.         }
  26.         echo '</tr>';
  27.  
  28.     endwhile; endif;
  29.  
  30.     echo '</table>';
  31. ?>
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement