plugins – why does an empty get_the_excerpt change get_the_ID to default homepage?


Using a post-carousel plugin, the following error is occurring after one line of code executes (the get_the_excerpt command only):

If the_excerpt for the current $post is empty, this is the result:

One line before the command, get_the_ID = 17457 (correct)

$pcp_post_content = get_the_excerpt();

One line after, get_the_ID = 9376 (incorrect — this is the default homepage / root URL)

If the_excerpt is NOT empty, this is the result (correct behavior):

get_the_ID = 17457 (correct)

$pcp_post_content = get_the_excerpt();

get_the_ID = 17457 (correct)

After some googling, I tried a suggestion to insert a setup_postdata() command, which did not change the outcome.

Since this is running in a somewhat complex plugin, I’m not 100% sure if it is running inside or outside the Loop, but it does work correctly if the_excerpt has content.

Any suggestions or learned experience with this kind of behavior?


user3810531 1 year 2021-07-27T13:22:14-05:00 0 Answers 0 views 0

Leave an answer