WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] 2.6 beta 1 get_posts bug? (9 posts)

  1. daleanthony
    Member
    Posted 6 years ago #

    Not sure if this is something to do with 2.6 beta 1 or if it's just a coincidence that this problem started just after I upgraded my installation.

    I have a page template (see code below) to show posts from category '8' which worked fine before, but now it seems to be showing posts from all categories. (live page at http://www.daleanthony.com/portfolio/)

    If this isn't a bug and it's just me being silly I would appreciate it if someone could offer some advice on how to fix this problem.

    <?php get_header(); ?>
    
    			<div id="content-container-wide">
    
    			<ul class="portfolioul">
    		 	<?php global $post; $myposts = get_posts('numberposts=9&offset=0&category=8'); foreach($myposts as $post) : setup_postdata($post); ?>
    
    				<li>
    				<img src="<?php echo get_post_meta($post->ID, "port-thumb", true); ?>" alt="<?php the_title(); ?> - Thumbnail"/>
    				<span class="portfolio-title"><?php the_title(); ?></span>
    				<span class="portfolio-work"><?php echo get_post_meta($post->ID, "port-project", true); ?></span>
    				<div class="portfolio-description"><?php the_content(''); ?></div>
    				</li>
    
    		 	<?php endforeach; ?>
    			</ul>
    		</div>
    
    		<div id="content-footer-wide"></div>
    
    </div>
    
    	<?php get_footer(); ?>

    Cheers.

  2. Lester Chan
    Member
    Posted 6 years ago #

    Erm, I got a feeling that method of retrieving post is quite backdated. Correct me if I am wrong. You should use query_post() instead.

  3. daleanthony
    Member
    Posted 6 years ago #

    @GamerZ thanks for the pointer, not quite sure how to get the template working with query_post though. It looks a bit more complicated than get_posts.

  4. Lester Chan
    Member
    Posted 6 years ago #

  5. MichaelH
    Member
    Posted 6 years ago #

  6. Lester Chan
    Member
    Posted 6 years ago #

    thanks Michael! Yours is a much better link =p

  7. daleanthony
    Member
    Posted 6 years ago #

    Any possibility someone could spare me 5 minutes to help re-write my portfolio page with query_posts? I've confused myself with it.

  8. Lester Chan
    Member
    Posted 6 years ago #

    <?php get_header(); ?>
    <div id="content-container-wide">
    	<ul class="portfolioul">
    <?php
    	query_posts('showposts=9&offset=0&cat=8');
    	while (have_posts()) : the_post();
    ?>
    
    <li>
    			<img src="<?php echo get_post_meta($post->ID, "port-thumb", true); ?>" alt="<?php the_title(); ?> - Thumbnail"/>
    			<span class="portfolio-title"><?php the_title(); ?></span>
    			<span class="portfolio-work"><?php echo get_post_meta($post->ID, "port-project", true); ?></span>
    			<div class="portfolio-description"><?php the_content(''); ?></div>
    		</li>
    <?php endwhile; ?>
    
    </div>
    <div id="content-footer-wide"></div>
    </div>
    <?php get_footer(); ?>
    The code is untested =D

  9. daleanthony
    Member
    Posted 6 years ago #

    @GamerZ Thanks for the help... I tried the code but it didn't work, played around with some of my wordpress settings and realised that a plugin was causing the problem which is probably why I couldnt get it working myself.

    Thanks again though!

Topic Closed

This topic has been closed to new replies.

About this Topic