Reputation: 1924
I'm trying to do execute a query with multiple parameters and can't figure out how to properly format the query. There isn't any documentation on combining queries in codex.wordpress.
I need to have the following in the query:
Here is my attempt:
<?php
$query = new WP_Query('cat=4', array('posts_per_page' => '4'), array('orderby' => 'date','order' => 'DESC'));
if ($query->have_posts()) : while ( $query->have_posts()): $query->the_post(); ?>
<li><a href="<?php the_permalink() ?>">
</li>
<?php endwhile; else: ?>
<p>Sorry, nothing</p>
<?php endif; wp_reset_postdata(); ?>
Any help is appreciated! Thanks!
Upvotes: 0
Views: 2398
Reputation: 10163
You can use &
to separate parameters like in URL GET parameters:
new WP_Query('cat=4&posts_per_page=4&orderby=date&order=DESC')
Or you can supply an array parameter:
new WP_Query(array(
'cat' => 4,
'posts_per_page' => 4,
'orderby' => 'date',
'order' => 'DESC'
))
Upvotes: 3