Title: Setting up post data
Last modified: August 19, 2016

---

# Setting up post data

 *  [nadine00](https://wordpress.org/support/users/nadine00/)
 * (@nadine00)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/setting-up-post-data/)
 * Hi There,
 * I have this query, and I need to switch it up a bit to set up the post data. 
   Right now it only pulls the post ID. Looking for suggestions on how to do that.
 *     ```
       <?php
       		  $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key = 'grade-type' AND meta_value like '%Post Secondary%'";
       		  $rows = $wpdb->get_results($query);
       		  foreach($rows as $row){
       		    echo "the id post id: " . $row->post_id;
       		    echo "<br />";
       		    echo $row->post_title; 
   
       		  }
       		?>
       ```
   
 * Thanks!
 * Nadine

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/setting-up-post-data/#post-1486489)
 * One example here:
    [http://codex.wordpress.org/wpdb#SELECT_a_Column](http://codex.wordpress.org/wpdb#SELECT_a_Column)
 *  Thread Starter [nadine00](https://wordpress.org/support/users/nadine00/)
 * (@nadine00)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/setting-up-post-data/#post-1486493)
 * Are you talking about everything from
 * > if ($postids) {….
 * down in that example or the whole thing? Is there a way I can set up post data
   without changing the query line?
 * Sorry, for the questions, its probably right in front of me….my brain is rebelling
   this morning.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/setting-up-post-data/#post-1486494)
 * you could try to use ‘setup_postdata()’:
 *     ```
       foreach($rows as $row){
             setup_postdata($row);
             echo "the id post id: " . $row->post_id;
             echo "";
             echo $row->post_title; 
   
       		  }
       ```
   
 *  Thread Starter [nadine00](https://wordpress.org/support/users/nadine00/)
 * (@nadine00)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/setting-up-post-data/#post-1486498)
 * Hmm. That doesn’t echo the post_title. It still only echos the post ID only.
 * I was also trying something like this, from the general query example, but it
   comes out blank:
 *     ```
       <?php
       		$query = "SELECT * FROM $wpdb->postmeta WHERE meta_key = 'grade-type' AND meta_value like '%Post Secondary%'";
       		$rows = $wpdb->get_results($query);
       		if ($rows) :
       			foreach ($rows as $post) :
       				setup_postdata($post);?>
   
       			<h2><a href="<?php the_permalink(); ?>" rel="bookmark"
       				title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
       		<?php
       			endforeach;
       		else :
       		?>
       		<h2> Not Found</h2>
       		<?php endif; ?>
       ```
   
 *  Thread Starter [nadine00](https://wordpress.org/support/users/nadine00/)
 * (@nadine00)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/setting-up-post-data/#post-1486534)
 * ok trying this:
 *     ```
       <?php
       		$querystr = "SELECT *
       		FROM $wpdb->postmeta, $wpdb->posts
       		WHERE meta_key = 'grade-type'
       		AND meta_value like '%Post Secondary%'
       		ORDER BY wposts.post_date DESC
       		";
   
       		$pageposts = $wpdb->get_results($querystr, OBJECT);
   
       		?>
   
       		<?php if ($pageposts): ?>
       		  <?php foreach ($pageposts as $post): ?>
       		    <?php setup_postdata($post); ?>
   
       		    <h4><?php the_title(); ?></h4>
   
       		    <?php endforeach; ?>
       		    <?php else : ?>
       		        <h2 class="center">There seems to be a glitch here.</h2>
   
       		     <?php endif; ?>
       ```
   
 * I am not a programmer, but I am trying. Any suggestions? I am not sure about 
   the above link’s example about joining.
 * thanks
 * Nadine

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Setting up post data’ is closed to new replies.

## Tags

 * [post data](https://wordpress.org/support/topic-tag/post-data/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [nadine00](https://wordpress.org/support/users/nadine00/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/setting-up-post-data/#post-1486534)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
