// WP QUERY $query=newWP_Query([ 'post_type'=>'press-release' "posts_per_page =>25, 'category_name'=>'health', ]); 这可以通过自定义Loop来实现。本质上,循环是WordPress用来显示某些文章的PHP代码。WordPress知道如何根据您的WP_Query自定义文章类型中的指定条件处理和格式化每个文章。
答案是:参数 post_type,此参数默认值为 post。 代码示例如下: $query=newWP_Query(array('post_type'=>'page') );$args=array('post_type'=>array('post','page','movie','book') );$query=newWP_Query($args); 如果,想不分辨文章类型,查询所有文章,则需要给 post_type 设值 'any'。 $query=n...
WP_Query 是WordPress 中用于查询文章和内容的类。通过使用不同的参数,您可以定制查询以满足您的特定需求。以下是一些常用的 WP_Query 参数以及它们的解释:post_type:指定要查询的内容类型,例如文章('post')、页面('page')、自定义内容类型(如 'portfolio')等。
$args = array( 'post_type' => 'post', 'meta_query' => array( array( 'key' => 'ID', 'value' => '100', 'compare' => '>' ) ) ); $query = new WP_Query( $args ); 在上面的代码中,我们使用了'meta_query'参数来指定我们要比较的字段和条件。'key'参数指定要比较的字段,这里我们...
wordpress默认会根据网址调用数据,不能满足我们所有建站要求,而WP_Query可以用于查询任何你想要的内容,相当于自定义数据调用。 wordpress的主循环 代码语言:javascript 代码运行次数:0 运行 AI代码解释 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title(); endwhile; endif; ...
$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(数组):一些标...
<?php $my_query=new WP_Query( array( 'post_type'=>'post', 'posts_per_page'=>10, 'orderby'=>'date', 'order'=>'DESC' ) ); if($my_query->have_posts()):while($my_query->have_posts()):$my_query->the_post(); ?> <a href="<?php the_permalink();?>"><?php the_tit...
To find a specific post (or set of posts), you have two options: p(int): Use post ID. name(string): Use post slug. You can use these parameters with any post type including posts, pages, attachments and custom post types. By default WordPress will query for the'post'post type and...
$first_post=get_post(1,ARRAY_A); $post_title=$first_post['post_title']; ?> 保存查询结果到数组中:get_posts() get_posts()函数可以运行查询并保存到数组中,当需要在不同的地方使用的时候,就可以拿出来使用。需要与WP_Query相同的参数,所以定制你自己喜欢的查询吧。(我们将会在之后重新回顾WP_Query的...
wp_reset_postdata(); $args是一个键/值对数组。这些对被命名为查询变量,并决定或影响实际的SQL查询。从插件查询数据库时,我们可能更喜欢使用pre_get_posts过滤器,如下例所示: functionmyplugin_pre_get_posts($query){ if(is_admin()|| !$query->is_main_query()){ ...