[wp-trac] [WordPress Trac] #36934: Use of get_the_excerpt($post) is broken if post has no excerpt and you are inside a loop

WordPress Trac noreply at wordpress.org
Sat Oct 1 02:16:49 UTC 2016


#36934: Use of get_the_excerpt($post) is broken if post has no excerpt and you are
inside a loop
-------------------------------------------------+-------------------------
 Reporter:  magicroundabout                      |       Owner:
     Type:  defect (bug)                         |  boonebgorges
 Priority:  normal                               |      Status:  reviewing
Component:  Formatting                           |   Milestone:  4.7
 Severity:  normal                               |     Version:  4.5
 Keywords:  has-patch needs-testing needs-unit-  |  Resolution:
  tests 4.7-early                                |     Focuses:  template
-------------------------------------------------+-------------------------

Comment (by boonebgorges):

 I think that @swissspidy has correctly identified that we need a fix
 that's broader than what was originally suggested by @magicroundabout. But
 I don't think that `setup_postdata()` is smart enough to do what's being
 asked of it.

 See [attachment:36934.2.diff]. I spent some time writing tests, to attempt
 to get my mind around what's happening in this, the very nether regions of
 The WordPress. The new test
 `test_should_respect_pagination_of_inner_post()` for `get_the_content()`
 is failing. Briefly, `WP_Query::setup_postdata()` can be passed a `$post`
 parameter. But checks like `$this->get( 'page' )`, `$this->is_page()`, and
 `$this->is_single()` assume that the `$post` is coming from the current
 `WP_Query` loop. If you are inside of a loop, and you pull up an unrelated
 `$post` and pass it to `get_the_excerpt()` - which is, if I understand it,
 the original idea in this ticket - the results will be affected by
 parameters of the loop. I've demonstrated this in the test by showing that
 the second page of the inner post is being fetched, because the `page`
 query_var of the outer loop is `2`.

 This suggests that a complete fix for this issue will mean abstracting
 `get_the_content()` even more. Perhaps the `$args` array should accept
 `page`, `more`, and `preview`, and only reference the globals (and thus
 `setup_postdata()` as fallbacks.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36934#comment:32>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list