WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get recent post problem (2 posts)

  1. roiabrazaldo
    Member
    Posted 10 months ago #

    I am trying to make a recent post base on multiple categories but not all categories..

    I have this code

    <?php
                    $args = array(
                        'numberposts' => '3',
                        'category' => '5');
    
                    $recent_posts = wp_get_recent_posts( $args, OBJECT );
                    foreach( $recent_posts as $recent ) : setup_postdata( $recent ); ?>
                        <div id="search-post">
                            <h1><a href="<?php echo get_permalink() ?>"><?php the_title(); ?></a></h1>
                            <p class="post-date">Posted on <span><?php the_time('F j, Y'); ?></span> at <span><?php the_time('g:i a'); ?></span></p>
                            <br />
                            <div class="search-content">
                                <?php the_excerpt();?>
                            </div>
                            <a class ="search-read" href="<?php echo get_permalink() ?>">Read</a>
                            <br />
                        </div>
                        <br /><br /><br />
                    <?php endforeach; wp_reset_postdata();?>

    problem is it results only the latest post regardless of categories and repeated it depending on numberposts.

    what suppose to be the problem with my code?

    I tried this
    'category' => '5' //no to avail
    'category' => '3, 5' //no to avail
    'category' => 'local, international' //no to avail

  2. roiabrazaldo
    Member
    Posted 10 months ago #

    Ok I manage to get what I wanted, I resort to use get_post instead

    <?php
    $args = array(
    'numberposts' => '3',
    'offset' => '0',
    'category' => '3,4',
    'orderby' => 'post_date',
    'order' => 'DESC');
    $postslist = get_posts( $args );
    foreach ($postslist as $post) : setup_postdata($post);
    ?>
    <div id="search-post">
    <h1>"><?php the_title(); ?></h1>
    <p class="post-date">Posted on <span><?php the_time('F j, Y'); ?></span> at <span><?php the_time('g:i a'); ?></span></p>

    <div class="search-content">
    <?php the_excerpt();?>
    </div>
    ">Read

    </div>

    <?php endforeach; wp_reset_postdata();?>

Reply

You must log in to post.

About this Topic

Tags

No tags yet.