doulao2916 2016-12-01 10:52
浏览 33

从类别中选择帖子时清空数组

I'm trying to get all posts in certain category, but I'm getting empty array. Here is my code:

$posts_args = array(
  'numberposts' => 6,
  'category' => 14,
  'orderby' => 'date',
  'order' => 'DESC',
  'post_type' => 'post'
);
$posts_array = get_posts($posts_args);

echo "<pre>";
print_r($posts_array);
echo "</pre>";

But in admin panel displaying properly.

  • 写回答

1条回答 默认 最新

  • dtdr57046 2016-12-01 11:02
    关注

    try this

             $posts_args=array( 
                       'posts_per_page' => 6,
                       'post_type' => 'post',  
                       'order'   => 'DESC',  
                         'tax_query' => array(
                          array(
                              'taxonomy' => 'category',
                              'field'    => 'term_id',
                              'terms'    => array( 14),                           
                             ),
                          )
                 );
               $posts_array = get_posts($posts_args);
    
               echo "<pre>";
               print_r($posts_array);
               echo "</pre>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算