为什么没有将query_posts()标记为已弃用?
-
-
这是一个很大的问题!对于遇到此问题的其他人,他们不知道为什么不应该使用query_posts(),[此处](http://wordpress.stackexchange.com/questions/50761/when-to-use-wp-query-query-posts-and-pre-get-posts)和[here](http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts/)是一些很好的入门问答.That is a great question! For others coming across this who don't know why you shouldn't use query_posts(), [here](http://wordpress.stackexchange.com/questions/50761/when-to-use-wp-query-query-posts-and-pre-get-posts) and [here](http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts/) are some good primer Q&A's on it.
- 2
- 2016-05-18
- Tim Malone
-
2 个回答
- 投票数
-
- 2016-05-18
我刚刚创建了一个新的追踪票,票#36874 提出不推荐使用
query_posts()
.是否接受它仍然是一个很好的问题.query_posts()
真正的大问题是,尽管关于为什么应该从不这样的主题确实写得很好,但它仍被插件和主题广泛使用. .我认为WPSE上最史诗般的帖子如下:弃用!==删除,因此弃用
query_posts()
不会阻止质量差的开发人员和不了解WordPress且使用不良代码的人质量教程作为指导.就像一些证据一样,在人们使用caller_get_posts
中的WP_Query
的地方,我们仍然会遇到几个问题?现在已经不推荐使用了多年.不过,在核心开发人员认为合适的任何时候,都可以删除不推荐使用的函数和参数,但是使用
query_posts()
绝不可能发生这种情况,因为这会破坏数百万个站点.所以是的,我们可能永远不会看到完全删除query_posts()
的情况-这可能导致这样的事实,即它很可能永远不会被弃用.虽然这是一个起点,但是必须记住,在WordPress中弃用某些内容不会停止其使用.
更新2016年5月19日
我举起的票证现已关闭,并标记为与 4岁 票证相同,该票证已作为 wontfix 关闭,并已重新打开并且仍然保持开放和未解决的状态.
似乎核心开发人员正在坚持这个古老的忠实小邪恶.每个有兴趣的人,这里是4岁的重复机票
I have just created a new trac ticket, ticket #36874, to propose the deprecation of
query_posts()
. Whether or not it will be accepted remains a good question.The real big issue with
query_posts()
is, it is still widely used by plugins and themes, even though there have been really good writings on the subject of why you should NEVER EVER use it. I think the most epic post here on WPSE is the following one:deprecation !== removal, so deprecating
query_posts()
will not stop its usage by poor quality devs and people in general who do not know WordPress and who use poor quality tutorials as guidelines. Just as some proof, how many questions do we still get here where people usecaller_get_posts
inWP_Query
? It has been deprecated for many years now.Deprecated functions and arguments can however be removed at any time the core devs see fit, but this will most probably never happen with
query_posts()
as this will break millions of sites. So yes, we will probably never see the total removal ofquery_posts()
- which might lead to the fact that it will most probably never get deprecated.This is a starting point though, but one has to remember, deprecating something in WordPress does not stop its use.
UPDATE 19 May 2016
The ticket I raised is now closed and marked as duplicate to a 4 year old ticket, which was closed as wontfix and was reopened and still remain open and unresolved.
Seems the core developers are hanging on to this old faithful little evil. Everyone interested, here is the duplicate 4year old ticket
-
他们为什么要关闭门票https://core.trac.wordpress.org/ticket/36874?请@PieterGoosen可以在票证中包含指向该线程的链接https://core.trac.wordpress.org/ticket/36874,因为此问题与票证1:1有关Why they closed the ticket https://core.trac.wordpress.org/ticket/36874? Please @PieterGoosen can you include the link to this thread in your ticket https://core.trac.wordpress.org/ticket/36874 since this question relates to the ticket 1:1
- 0
- 2016-05-19
- prosti
-
@prosti似乎已被标记为重复,因为此问题已被提出... ** 4年前** [在这里找到](https://core.trac.wordpress.org/ticket/19631).@prosti Looks like it was marked as duplicate as this issue has already been brought up... **4 years ago** [found here](https://core.trac.wordpress.org/ticket/19631).
- 0
- 2016-05-19
- Howdy_McGee
-
- 2016-05-19
[有点rant]
在这一点上,始终存在的核心哲学是什么都不会被真正弃用.弃用通知虽然很不错,但是如果实际上在某个时候不会删除该函数,它将被忽略.很多人不使用
WP_DEBUG
进行开发,如果没有实际的损坏,他们不会注意到该通知.OTOH手,此功能类似于
goto
语句.我个人从未使用过goto
,但我可以理解指向默认情况下并不邪恶的某些情况的论点.query_posts
也是如此,这是设置进行简单循环所需的所有全局变量的简单方法,并且在ajax或rest-api上下文中很有用.我也永远不会在那些情况下使用它,但是我可以看到,更多的是编码风格的问题,而不是函数本身就是邪恶的.再深入一点,主要问题是根本需要设置全局变量.这是主要问题,而不是帮助设置它们的一个功能.
[somewhat rant]
It is the standing core philosophy at this point that nothing is truly deprecated. Deprecation notice, while it is a nice to have, is just going to be ignored if the function will not actually be dropped at some point. There are many people that do not develop with
WP_DEBUG
on and will not notice the notice if there will not be an actual breakage.OTOH hand, this function is like
goto
statement. Personally I never (for smaller definition then expected) usedgoto
but I can understand the arguments pointing to some situation in which it is not evil by default. Same goes withquery_posts
, it is a simple way to set up all the globals required to make a simple loop, and can be useful in ajax or rest-api context. I would never use it in those contexts as well, but I can see that there, it is more of an issue of style of coding then a function being evil by itself.Going a little deeper, the main problem is that globals need to be set at all. That is the main problem not the one function that helps setting them.
-
为了进行比较," query_posts"确实比辅助查询慢(阅读:不是主查询).And for the comparison, is really `query_posts` slower than a secondary query (read: not the main query).
- 0
- 2016-05-19
- prosti
-
@prosti,因为它只是设置并运行wp_query,它可以慢多少?当然会有一些开销,但是我们这里可能要讲几毫秒.当然,这假定您在默认情况下WP不提供查询的地方使用它.在做错事的地方,不是'query_posts'本身,而是在WP加载时完成的无用查询@prosti, as it just sets and runs a wp_query, how much slower can it be? sure there is some overhead but we probably talking miliseconds here. This of course assumes you use it in places where WP do not provide a query by default. In places where it does it is bad, not the `query_posts`itself but the useless query that was done when WP was loading
- 0
- 2016-05-19
- Mark Kaplun
从技术上讲,有两个
query_posts()
函数.一个query_posts()
实际上是WP_Query::query_posts()
,另一个在全局空间中.出于理智:
如果全局
query_posts()
是那个"邪恶的"为什么不被弃用?或者为什么不将其标记为
_doing_it_wong
.