• Resolved technguide

    (@technguide)


    Let’s say i want to get the latest post from ‘liveblog’ category, which part do i edit?

    <?php require('../wp-blog-header.php');?>
    <html>
        <?php
            $args = array( 'numberposts' => 1,
                            'post_status'=>"publish",
                            'post_type'=>"post",
                            'orderby'=>"post_date",
                            'category'=>"liveblog");
            $postslist = get_posts( $args );
    
            foreach ($postslist as $post) : setup_postdata($post);
            ?>
        Redirecting to <b>
        <?php
            echo the_permalink();
            echo "</b>. ";
            ?>
        If redirection doesn't take place within 5 seconds, click
        <a href = "<?php the_permalink()?>">here</a>.
        <br/><br/>
        <b>Post Name</b> : <?php the_title();?><br/>
        <b>Date Posted</b> : <?php the_date();?><br/>
        <script>
            //location = "<?php the_permalink()?>";
        </script>
        <?php endforeach; ?>
    
    </html>
Viewing 2 replies - 1 through 2 (of 2 total)
  • First, I believe that ‘posts_per_page’ is preferred over ‘numberposts’.

    Second the parameter for the category should probably be ‘category_name’ instead of just ‘category’. But, use the slug even though the parameter is category_name!

    Thread Starter technguide

    (@technguide)

    Awesome! I’ve edited it to be like this

    $args = array( 'posts_per_page' => 1,
                            'post_status'=>"publish",
                            'post_type'=>"post",
                            'orderby'=>"post_date",
                            'category_name'=>"liveblog-apple-keynote");

    and it worked flawlessly. Thank you once again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How Do I Only Select One Post From One Category?’ is closed to new replies.