【问题标题】:Show posts by slug显示 slug 发表的帖子
【发布时间】:2014-07-02 06:13:43
【问题描述】:

我正在尝试使用 slug 描述来检索特定的帖子。

所有帖子(在本例中为产品)都存储在“投资组合”中,其中“汽车”是其中之一 过滤器用作类别。

我已经在网上看到了一些相关的帖子,但由于我缺乏 PHP 知识,目前无法弄清楚,并想在这里尝试一下。

这是使用的代码。任何帮助表示赞赏,谢谢!

// Create a new `WP_Query()` object

$wpcust = new WP_Query(
    array(
        'post_type' => array('portfolio'),
        'tag_slug__in' => array('automotive'),
        'post__not_in' => array(1366, 1359, 1353),
    'orderby' => 'rand',
        'showposts' => '4' )
    );

【问题讨论】:

  • 你遇到了什么问题?

标签: php wordpress


【解决方案1】:

您可以在 Wordpress 查询中使用以下参数:http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

  • post_type 可以是数组或字符串。
  • tag 应该是 细绳。
  • post__not_in 应该是一个数组。
  • orderby 应该 成为一个字符串。
  • showposts 已弃用。你需要使用 posts_per_page 代替。 posts_per_page 应该是一个整数。

posts_per_page (int) - 每页显示的帖子数(在 2.1 版中可用,已替换 showposts 参数)。使用 'posts_per_page'=>-1 显示所有帖子(使用 -1 值忽略 'offset' 参数)。如果使用此参数后关闭分页,则设置'paged'参数。

你的代码应该是:

$wpcust = new WP_Query(
    array(
        'post_type' => 'portfolio',
        'tag' => 'automotive',
        'post__not_in' => array(1366, 1359, 1353),
        'orderby' => 'rand',
        'posts_per_page' => '4' 
    )
);

【讨论】:

    【解决方案2】:

    这可能会有所帮助:-

    $wpcust = new WP_Query(
        array(
            'post_type' => 'portfolio',
            'tag_id' => '54',
            'post__not_in' => array(1366, 1359, 1353),
        'orderby' => 'rand',
            'posts_per_page' => '4' )
        );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      • 2013-01-19
      • 2021-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多