简体   繁体   中英

Wordpress Loop for pages AND posts

I know it's possible to have multiple post loops on the same page, what I'm trying to achieve is having a single loop that will grab all pages and posts and then display them in chronological order.

So far I've only been able to loop for one or the other using WP_Query , two separate loops isn't an option as I need to be able to sort the output by date.

Does anyone have any experience doing something similar? Any advice on where to start would be greatly appreciated.

try:

$args = array(
'post_type' => array('carmarket', 'bikemarket') // or 'post', 'page' etc whatever you want

);
$query = new WP_Query( $args );

ref: http://codex.wordpress.org/Class_Reference/WP_Query

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