0

我正在尝试使用多个参数执行查询,但无法弄清楚如何正确格式化查询。没有任何关于在codex.wordpress中组合查询的文档。

我需要在查询中包含以下内容:

  • 类别 id - 仅显示来自某个类别(或类别、数组)的帖子
  • 每页的帖子数
  • 按日期排序 DESC
  • 使用帖子 ID 排除帖子

这是我的尝试:

   <?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(); ?>

任何帮助表示赞赏!谢谢!

4

1 回答 1

3

您可以使用&URL GET 参数中的参数来分隔参数:

new WP_Query('cat=4&posts_per_page=4&orderby=date&order=DESC')

或者您可以提供一个数组参数:

new WP_Query(array(
    'cat' => 4,
    'posts_per_page' => 4,
    'orderby' => 'date',
    'order' => 'DESC'
))
于 2013-09-15T15:33:07.120 回答