wordpress如何调用具有相同自定义栏目名称及值的文章

  • 时间:2020-05-22 15:47:15
  • 分类:网络文摘
  • 阅读:153 次

在 wordpress 中,利用query_posts() 或 wp_query()可以同时使用多个 meta_key与 meta_value 来查询多个自定义字段及值。如果想要调用输出具有相同自定义栏目名称及值的文章,可以使用下面的wordpress技巧:

wordpress如何调用具有相同自定义栏目名称及值的文章

用如下代码替换默认的主循环,并修改其中的自定义栏目名称及值。

  1. $args = array(
  2.     'posts_per_page' => 10,      // 显示多少条
  3.     'paged' => $paged,           // 当前页面
  4.     'orderby' => 'date',         // 时间排序
  5.     'order' => 'desc',           // 降序(递减,由大到小)     
  6.     'meta_query' => array(
  7.         array(
  8.             'key' => 'key1',     // 你的使用的自定义字段1
  9.             'value' => 'value1'  // 自定义字段1对应的值
  10.         ),
  11.         array(
  12.             'key' => 'key2',     // 你的使用的自定义字段2
  13.             'value' => 'key2'    // 自定义字段2对应的值
  14.         )
  15.     )
  16. );
  17. query_posts($args);
  18. while (have_posts()) : the_post();
  19.     // 循环内容;
  20. endwhile;
推荐阅读:
The Contiguous Binary Array with Equal Numbers of Ones and Zeros  Microbit Programming: Showing a Running Pixel on the LED  How to Print Immutable Linked List in Reverse using Recursion or  The Most Useful Tools for Reverse Phone Lookup  How to Solve the WIFI (Wireless Networks) Intermittency Issues?  How to Reverse a Linked List in Javascript?  Bash Function to Check if a Kubernetes Pod Name is Valid  VBScript Function to Convert an Integer to Binary String Represe  Find Maximum Connected Colors (Values) in a 2D Grid using DFS or  Algorithms to Shift a 2D Grid/Matrix In-Place 
评论列表
添加评论