WordPress.org

Ready to get started?Download WordPress

Forums

get_posts only shows first post (4 posts)

  1. shadowpwner
    Member
    Posted 5 years ago #

    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.

  2. racer x
    Member
    Posted 5 years ago #

    I think you need to use category_name=Clubs.

  3. shadowpwner
    Member
    Posted 5 years ago #

    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.

  4. MichaelH
    Member
    Posted 5 years ago #

    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>

Topic Closed

This topic has been closed to new replies.

About this Topic