简体   繁体   中英

Wordpress - call wp_get_recent_post twice on one page

I need to call the wp_get_recent_post a second time on the same page.

Basically I need to call this code twice(with different categories).

$args = array( 'numberposts' => '4', 'category_name' => 'category', 'orderby' => 'date' );
    $recent_posts = wp_get_recent_posts( $args );

    foreach( $recent_posts as $recent ):
              ....
        endforeach;

I read about rewind_posts() but I don't understand where to put it (as the examples in the docs are using other functions to get the posts data). Could you explain the best way to deal with this?

Links to clear examples would be appreciated.

thanks!

I'm not sure what your question is; have you tried calling this twice? What happened? That said I think you're going to need to add wp_reset_postdata() right after each endforeach; to keep the rest of your page clean.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM