Excerpt functions break when a shortcode calls wp_reset_postdata
-
I have a shortcode which runs a custom query, then calls
wp_reset_postdata()
, which resets the$post
variable back to its original value.Inside the
relevanssi_do_excerpt
function, there is a hack which sets$post
to the post to generate an excerpt for.When
$content = apply_filters( 'the_content', $content );
is run inside this function, the shortcode executes. However,wp_reset_postdata
doesn’t do anything, because you’re not inside a properly set up query. This means, after this line, the$post
variable is set to a completely different item (the last one used by the executed shortcode).This causes all sorts of problems, but the particular one is that the
relevanssi_excerpt_content
filter is then called with a completely wrong$post
parameter.
- The topic ‘Excerpt functions break when a shortcode calls wp_reset_postdata’ is closed to new replies.