• Hello guys!

    So I have a problem, here’s my code first:

    <?php
     global $school;
     $myposts = get_posts('numberposts=6&offset=0&category=8');
     foreach($myposts as $school) :
       setup_postdata($school);
     ?>
        <li><a href="<?php the_permalink(); ?>"><span class="date"><?php the_time('m.d.Y'); ?></span><br /><span class="event"><?php the_title(); ?></span></a></li>
     <?php endforeach; ?>
     </ul> 
    
    	<div id="bulletin-clubs">
    	  <ul class="rss"><li><a href="index-2.html">&nbsp;</a></li></ul>
    	  <h1><a href="index-2.html">clubs</a></h1>
    	  <div class="bulletin-items">
    	    <ul id="bulletin-clubs-list">
    	     <?php
     global $school1;
     $myposts1 = get_posts('numberposts=6&offset=0&category=Clubs');
     foreach($myposts1 as $school1) :
       setup_postdata($school1);
     ?>
        <li><a href="<?php the_permalink(); ?>"><span class="date"><?php the_time('m.d.Y'); ?></span><br /><span class="event"><?php the_title(); ?></span>hi</a></li>
     <?php endforeach; ?>
     </ul>

    This posts the first result of Category 8 in both get_posts queries.

    A demo can be found here: bagofhacks.com The two columns on the bottom are where the code’s at.

    Thanks in advance for all the help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I think you need to use category_name=Clubs.

    Thread Starter shadowpwner

    (@shadowpwner)

    Hey, thanks for the reply, but I don’t think that’s it. I just tried it, and it still returns the same result, and the the column that has the right ID only shows 6 of the same posts.

    Use $post in your foreach and setup_postdata statements

    <?php
     global $school;
     $myposts = get_posts('numberposts=6&offset=0&cat=1');
     foreach($myposts as $post) :
       setup_postdata($post);
     ?>
        <li><a href="<?php the_permalink(); ?>"><span class="date"><?php the_time('m.d.Y'); ?></span><br /><span class="event"><?php the_title(); ?></span></a></li>
     <?php endforeach; ?>
     </ul> 
    
    	<div id="bulletin-clubs">
    	  <ul class="rss"><li><a href="index-2.html">&nbsp;</a></li></ul>
    	  <h1><a href="index-2.html">clubs</a></h1>
    	  <div class="bulletin-items">
    	    <ul id="bulletin-clubs-list">
    	     <?php
     global $school1;
     $myposts1 = get_posts('numberposts=6&offset=0&cat=10');
     foreach($myposts1 as $post) :
       setup_postdata($post);
     ?>
        <li><a href="<?php the_permalink(); ?>"><span class="date"><?php the_time('m.d.Y'); ?></span><br /><span class="event"><?php the_title(); ?></span>hi</a></li>
     <?php endforeach; ?>
     </ul>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_posts only shows first post’ is closed to new replies.