Forums

Setting up post data (6 posts)

  1. nadine00
    Member
    Posted 2 years ago #

    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

  2. MichaelH
    Volunteer
    Posted 2 years ago #

  3. nadine00
    Member
    Posted 2 years ago #

    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.

  4. alchymyth
    The Sweeper
    Posted 2 years ago #

    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; 
    
    		  }
  5. nadine00
    Member
    Posted 2 years ago #

    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; ?>
  6. nadine00
    Member
    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic