通过帖子ID获取WordPress内容的最佳/有效方法是什么,为什么?
-
-
我想说的是代码,函数调用和查询最少的方法.您做了什么来尝试剖析这些内容?您的基准测试结果如何?您是否在内容中加入了oEmbeds和Shortcode,这有关系吗?收集数据后,您将在哪里使用这些数据?您应该为问题提供更好的背景,以获得更有用的答案.I'd say the way with the least amount of code, function calls, and queries. What did you do to try and profile these? What are the results of your benchmarks? Did you account for oEmbeds and Shortcode in your content - does that matter? Where are you using this data after you gather it? You should supply better context to the question for a more useful answer.
- 1
- 2016-11-10
- jgraup
-
另外,我想我还记得有一些要在内容上运行的过滤器-http://wordpress.stackexchange.com/a/245057/84219Also, I think I remember there being a few filters to run on the content - http://wordpress.stackexchange.com/a/245057/84219
- 0
- 2016-11-10
- jgraup
-
@jgraup我写了这个问题的答案后问了这个问题(http://wordpress.stackexchange.com/questions/245661/generate-meta-name-description-using-the-page-title-first-sentence-of-身体/)@jgraup I asked this question after writing a answer for this question (http://wordpress.stackexchange.com/questions/245661/generate-meta-name-description-using-the-page-title-first-sentence-of-body/)
- 0
- 2016-11-10
- Ranuka
-
正如@jgraup所说,这个问题缺乏上下文,"最佳"只能在特定上下文中针对不平凡的任何事物来决定as @jgraup say, this question lacks context and "best" can be decided only in a specific context for anything which is not trivial
- 0
- 2016-11-10
- Mark Kaplun
-
1 个回答
- 投票数
-
- 2016-11-10
您提供的用于比较的方法几乎相同,只是API稍有不同,并且是否应用了
the_content
过滤器.通常应在循环中使用
get_the_content()
,该代码可以正确处理拆分为页面等内容.要检索原始内容,通常使用
get_post_field()
,但是任何进一步的处理(例如the_content
过滤器)在很大程度上取决于特定的目的检索内容以及您将如何处理它.PS请注意,许多扩展很笨拙,并且在循环外执行的
the_content
过滤器上多次中断.The methods you offer for comparison are pretty much the same, with minor API differences and whether
the_content
filters are applied.Within the loop
get_the_content()
should typically be used, which properly handles split into pages and so on.To retrieve raw content
get_post_field()
is generally suitable, but any further processing (such asthe_content
filters) heavily depends on specific purpose of retrieving content and what you are going to do with it.PS take note that many extensions out there are dumb and variously break on
the_content
filter executed outside of loop / more than once.
我只是想通过帖子ID获取WordPress内容.我发现以下三种通过帖子ID获取WordPress内容的方法.(我在该网站上找到的以下所有方法.)
方法01:
方法02:
方法03:
什么是最好的/最有效的方法?为什么?