$query=newWP_Query('author_name=rami');// 根据用户名查找 $query=newWP_Query('author=2,6,17,38');// 查询多个人的文章 $query=newWP_Query('author=-12');// 查询不属于某个人的文章 可以通过减号“-”来排除某位作者。 $query=newWP_Query('cat=4');// 按分类ID $query=newWP_Query('...
$query = new WP_Query( array( ‘category__not_in’ => array( 2, 6 ) ) ); 标签获取关于标签的文章,可以使用 7 个参数:tag(字符串):标签别名 tag_id(整数):标签 ID tag__end(数组):一些标签 ID tag__in(数组):一些标签 ID tag_slug__and(数组):一些标签别名 tag_slug__in(数组):一些标...
$query=newWP_Query($args); // 判断查询的结果 if($query->have_posts()){ // 通过查询的结果,开始主循环 while($query->have_posts()){ $query->the_post(); // Contents of the queried post results go here. } } // 重置请求数据 wp_reset_postdata(); ?> 你可以在查询的时候去定义需要...
高级自定义字段库(Advanced Custom Fields,简称ACF)是一个流行的WordPress插件,它允许用户轻松地创建和管理自定义字段,从而扩展WordPress的功能。wp_query是WordPress中的一个核心函数,用于执行自定义数据库查询。结合ACF和wp_query,可以实现复杂的查询和数据展示。 基础概念 高级自定义字段库(ACF): ACF允许你在WordPress...
Query argument Query itself The Loop Post data reset 查询中最关键的部分之一是参数(称为WP_Query args)。该参数通知WordPress您要从数据库中检索哪些数据。该参数不会显示您的所有文章内容,而是会在您的循环中设置一些条件。 您可能注意到了前面示例中的 ($args) 行。这是您将包含查询参数的地方。
$query=newWP_Query($args); // Check that we have query results. if($query->have_posts()){ // Start looping over the query results. while($query->have_posts()){ $query->the_post(); // Contents of the queried post results go here. ...
在使用WP_Query循环获取WooCommerce产品属性时,可以通过以下步骤实现: 首先,需要创建一个新的WP_Query对象,指定查询参数。可以使用'post_type'参数将查询限制为WooCommerce产品类型。例如: 代码语言:txt 复制 $args = array( 'post_type' => 'product', // 其他查询参数 ); $query = new WP_Query( $args )...
$query = new WP_Query($args);meta_key 和meta_value:用于根据自定义字段的键和值进行查询。$args = array( 'meta_key' => 'price', 'meta_value' => 100, ); $query = new WP_Query($args);tax_query:用于根据自定义分类法(taxonomy)进行查询。$...
paged 分页时显示第几页,需设值获取当前页的分页码:get_query_var('paged') 排序 order 升序降序,默认为'DESC'降序,ASC升序 orderby 按什么排,比如按ID<?php $args = array( //作者参数 - Show posts associated with certain author. //http://codex.wordpress.org/Class_Reference/WP_Query#Author_Param...
// Instantiate new query instance. $my_query=newWP_Query($args); ?> Pass this query in a loop and you’re good to go! Example #2: “Latest Posts From This Category” (Except the Current Post) Let’s say that you want to create a loop under each post in their single post pages...