php - 我如何在 WP_Query 中执行 LIMIT 1、2

标签 php wordpress

我正在使用 Wp_Query 方法,我想了解是否有任何参数可以限制我的查询。 我尝试在 WP_Query 中使用 LIMIT 1,2。 感谢您的提前!

$args = array(
'post_type'     => 'post',
'post_status'   => 'publish',
'orderby' => 'ID',
'order'   => 'DESC',
'meta_query'    => array(
                        array(
                            'key'     => 'featured',
                            'value'   => 'evet',
                            'compare' => '='
                        )
                    )
);

// The Query
$the_query = new WP_Query( $args );

最佳答案

您可以为 WP_Query() 使用 posts_per_pageoffset 参数,例如:-

$query = new WP_Query( array( 'posts_per_page' => 5, 'offset' => 3 ) );

更多:- http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

你要求 LIMIT 1,2(表示偏移量,计数(多少行))所以

posts_per_page = count
offset = offset

关于php - 我如何在 WP_Query 中执行 LIMIT 1、2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28090260/

相关文章:

php - 如果选中复选框,则删除类

html - WordPress/HTML 代码 : Pictures don't get displayed properly on mobile view

wordpress - 弹窗评论无索引

javascript - 在 WordPress 编辑器中突出显示或下划线搜索词

html - 在第三个子菜单后重置 css 属性

php - 如何使用Elasticsearch 1.4.5中必须使用范围和术语进行过滤的方法

php - 在 Symfony 中上传后如何保留原始文件名

php - 解析 Amazon MWS Scratchpad 响应

php - 使用已知的用户名和密码登录 Facebook API

php - 一个数据库包含 2 个 WordPress 站点的不同选项表