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$postvariable back to its original value.Inside the
relevanssi_do_excerptfunction, there is a hack which sets$postto 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_postdatadoesn’t do anything, because you’re not inside a properly set up query. This means, after this line, the$postvariable 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_contentfilter is then called with a completely wrong$postparameter.
The topic ‘Excerpt functions break when a shortcode calls wp_reset_postdata’ is closed to new replies.