ewels / CPT-Bootstrap-Carousel

WordPress plugin which generates a custom post type for choosing images and content. Outputs Bootstrap Image Carousel (slider) HTML from a shortcode.
http://wordpress.org/plugins/cpt-bootstrap-carousel/
GNU General Public License v2.0
51 stars 36 forks source link

Failure when post doesn't have an Excerpt #95

Open ewels opened 5 years ago

ewels commented 5 years ago

Problem with the latest release of the plugin, reported by email:


One of our clients uses your WP plugin for their Image Rotator on the home page (post ID 94), and updating to your latest version (1.10) from 1.9.1 is causing an issue with the images displaying.

From what I can tell, our issue is from the updated file, cptbc-frontend.php (~ line 74-81), and with the changed variable $post_id to get_the_ID() function:

https://github.com/ewels/CPT-Bootstrap-Carousel/blob/21d7d9f4c21794e6636648c29ec101fb1b8b951a/trunk/cptbc-frontend.php#L73-L81

An issue occurs if the image carousel item doesn't have an "Excerpt". Then the line $content = get_the_exceprt(); seems to revert to the global $post for the home page (post ID 94) and then updates the global $post so that get_the_ID() then returns the home page ID and not the image carousel item (therefore not displaying the image).

I think you should revert back to your variable $post_id, or check to make sure you're looking at the right post_id, or possibly rename the excerpt for the image carousel items and create a new function to retrieve that attribute. Unsure on the best fix here.

This may be helpful, add this function to your cpt-bootstrap-carousel.php file: https://www.codee.io/wordpress-excerpt-using-post-id/

then change $content = get_the_excerpt() to that new function custom_get_the_excerpt($post_id);

ewels commented 5 years ago

I suspect that this is an older issue and not something that came about with the latest release. Sounds very similar to the bug report here: https://wordpress.org/support/topic/cpt-bootstrap-carousel-caption-is-now-including-content-from-page/