【问题标题】:Grab more than one category with wordpress $args使用 wordpress $args 获取多个类别
【发布时间】:2013-10-15 05:09:53
【问题描述】:

我有这个代码:

<?php
global $post;
$args = array( 'numberposts' => 4, 'category' => 15 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); ?>

问题是我想要获取的不仅仅是类别编号 15。只需将它们添加到 15 旁边,例如 15、18 或“15,18”都行不通。 有任何想法吗? 谢谢

【问题讨论】:

  • 使用 '15,18' :它会起作用,我已经在下面回答了。

标签: php wordpress


【解决方案1】:

试试这个:它在我的项目中工作。

<?php
global $post;
$args = array( 'numberposts' => 4, 'category' => '15,8');
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); ?>

谢谢。

【讨论】:

  • 它有效。我以为我试过这个,但我做错了什么。谢谢。
猜你喜欢
  • 2017-04-26
  • 1970-01-01
  • 1970-01-01
  • 2020-08-28
  • 1970-01-01
  • 1970-01-01
  • 2013-12-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多