- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
关于效率的问题。使用 wp_query($args)
和 $query = new WP_Query($args)
有什么区别?在效率/SQL 查询数量上有什么不同吗?一种总是比另一种更好,还是在某些情况下更喜欢一种风格?
例如,如果我想要一个基于类别的包含 3 列的复杂页面,那么以下两个示例有何不同?
$query = new WP_Query("category_name=Issue 1")
while ($query->have_posts())....
对比
rewind_posts()
query_posts("category_name=Issue 1")
while(have_posts())...
最佳答案
没有。
一个只是调用另一个,这是来自 WP source .
function query_posts($query) {
$GLOBALS['wp_query'] = new WP_Query();
return $GLOBALS['wp_query']->query($query);
}
天哪,我喜欢 WP,它太棒了。失败。
关于php - new WP_query() 和 query_posts() 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17999989/
我正在尝试通过自定义字段使用 query_posts 函数对我的结果进行排序。 这是我编辑过的 query_posts() 函数: query_posts( "post_type=produkte&"
我正在尝试过滤我的帖子,仅显示具有“型号”字段自定义值的帖子,同时按另一个名为“价格”的自定义字段对帖子进行排序。 这是我正在使用的函数(不起作用): 此功能仅显示模特,但不会按价格对帖子进行排序。
我读到应该避免使用 query_posts(),而使用 wp_query() 和 pre_get_posts()。我对弄乱循环没有信心,也不完全理解法典。 下面的代码是否使用了 query_posts
我想创建一个 query_posts,我首先按自定义字段的数量(Facebook Likes)排序,然后按日期排序。但我不知道如何。 我的查询看起来像那个 atm: $social_query = a
我需要从显示的帖子中排除一个类别。我注册了分类法:投资组合类别并在组合类别下添加了一个类别:配件(目录 ID 19) 如何排除配件类别中的帖子不显示?我尝试过:'category' => -19,但它
在此页面http://atthy.com/blog/ 我使用自定义模板来显示博客文章列表,因为我使用 home.php 文件来显示自定义主页。我用query_posts()因为它是自定义模板。我在 w
我希望使用 query_posts 运行查询,以便查看元字段。我之前已经这样做过一次并达到了我想要的结果,但现在由于某种原因在方程中添加一个额外的字段不会返回任何结果。 下面的查询返回所有附件,其中l
这是我的示例站点,http://box7.host1free.com/~avodes/我在博客文章 (blog.php) 上遇到了问题。即使我点击了“旧条目”链接,仍然会显示 5 个新帖子而不是旧帖子
我正在尝试使用以下代码进行分页,但没有成功: $page = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array(
我正计划为 Wordpress 主题制作一个模板页面,它将在页面的内容部分加载 5 个单独的“模块”。这些模块旨在分别显示不同类别的最新 4 篇帖子(工作方式与 this 类似)。 在循环中处理此问题
我的情况有点复杂,我会尽量简洁地解释一下。 我目前正在使用 query_posts 修改我网站上自定义页面上的主查询,据我所知,效果很好,尽管我已经了解到使用 query_posts 是不好的做法由于
query_posts(array( 'post_category' => 'xyz', 'post_type' => 'abc',
我正在尝试构建一个查询,该查询将从两个不同的 post_types 中获取信息。我有问答视频和律师事务所。这些是通过 WordPress 插件通过自定义帖子类型管理器 (CCTM) 设置的。当律师事务
下面的查询在我的网站上运行一个特色轮播。我希望轮播仅显示包含图像的帖子。我到处搜索,找不到解决方案。请帮忙! query_posts(array('post_type' => 'ad_listing'
我试图获取特定日期(即今天)的所有帖子,但由于某种原因它只返回了一个。 $wp_posts = query_posts(array( 'cat' => 4,
我正在使用 admin-ajax.php 执行 AJAX 请求,据此我根据选中的复选框过滤帖子。它工作得很好,尽管我正在努力寻找一种方法来返回每个帖子的元详细信息。 我只是使用 query_posts
我正在使用 query_posts获取最受欢迎的帖子列表。我正在使用几种自定义帖子类型,而不是将所有这些类型都包含在查询中,我想要一个只获取所有这些类型的查询,如果我创建更多。 这就是我所拥有的: q
$posts = query_posts(array('post_type'=>'sedan', 'category'=>'1', 'posts_per_page'=>'4')); category上
关于效率的问题。使用 wp_query($args) 和 $query = new WP_Query($args) 有什么区别?在效率/SQL 查询数量上有什么不同吗?一种总是比另一种更好,还是在某些
关于效率的问题。使用 wp_query($args) 和 $query = new WP_Query($args) 有什么区别?在效率/SQL 查询数量上有什么不同吗?一种总是比另一种更好,还是在某些
我是一名优秀的程序员,十分优秀!