wordpress如何调用具有相同自定义栏目名称及值的文章
- 时间:2020-05-22 15:47:15
- 分类:网络文摘
- 阅读:132 次
在 wordpress 中,利用query_posts() 或 wp_query()可以同时使用多个 meta_key与 meta_value 来查询多个自定义字段及值。如果想要调用输出具有相同自定义栏目名称及值的文章,可以使用下面的wordpress技巧:

用如下代码替换默认的主循环,并修改其中的自定义栏目名称及值。
- $args = array(
- 'posts_per_page' => 10, // 显示多少条
- 'paged' => $paged, // 当前页面
- 'orderby' => 'date', // 时间排序
- 'order' => 'desc', // 降序(递减,由大到小)
- 'meta_query' => array(
- array(
- 'key' => 'key1', // 你的使用的自定义字段1
- 'value' => 'value1' // 自定义字段1对应的值
- ),
- array(
- 'key' => 'key2', // 你的使用的自定义字段2
- 'value' => 'key2' // 自定义字段2对应的值
- )
- )
- );
- query_posts($args);
- while (have_posts()) : the_post();
- // 循环内容;
- endwhile;
Blogging From the Road: Japan Edition How to Redesign Your Blog for Improved User Experience Yes, It’s Possible to Grab Loans When Working as a Freelancer 2017 Most Unique and Friendliest CMS for Small Businesses 5 Easy Steps to Writing the Perfect Guest Post A Compilation of the Best Content Creation Strategies from 43 Ex Why Writing Internships Are an Underrated Way to Become a Great Compute Number of Lines To Write String (Wordwrap) How to Reverse Words in a String? Design a Logger Rate Limiter in C++/Java
- 评论列表
-
- 添加评论