Seriously-Simple-Podcasting icon indicating copy to clipboard operation
Seriously-Simple-Podcasting copied to clipboard

WP Forums: Wrong Title When Using Shortcode

Open itsjusteileen opened this issue 5 years ago • 3 comments

Describe the bug included the following shortcode into the content of the post and the title of the ID that this display-posts shortcode uses was used as the title for my post within the podcast feed.

As soon as I removed the shortcode it used the correct title.

[display-posts id="8537" include_content="true" include_title="false"]

The problem is that when you get the content and the content has a shortcode that has a post ID – the global post id seems to be reset. Hoping to come up with a PR to fix this issue somehow.

Additional context https://wordpress.org/support/topic/wrong-title-when-using-any-shortcode/#post-12704158

itsjusteileen avatar Apr 20 '20 20:04 itsjusteileen

This is apparently due to the display-posts changing the global context of the post, even though the display-posts plugin apparently resets the context properly. Given that this has been reported by several forum users using different shortcodes within the podcast body, I think it might be appropriate to deal with this within SSP, even though I think you could argue that it should be fixed upstream.

cmcnulty avatar Apr 21 '20 13:04 cmcnulty

Took me a few tries to get the commit just right. Let me know if you have any questions about reproducing the issue. There are two ways to solve it the other way involves grabbing all of the relevant data (title, permalink, possibly others) which are affected by the global-state-change, and caching them before the state changes, but that seemed ugly. The other way, of course, would be to try to figure out what's going on with the display-posts & wp engine... but I suspect that it's a non-trivial fix.

cmcnulty avatar Apr 24 '20 05:04 cmcnulty

... The problem is that when you get the content and the content has a shortcode that has a post ID the global post id seems to be reset. Hoping to come up with a PR to fix this issue somehow.

For the record, you can reproduce the bug regardless of the parameters of the shortcode - you don't need to identify the post-id in the shortcode parameters.

cmcnulty avatar Apr 24 '20 05:04 cmcnulty