Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure when post doesn't have an Excerpt #95

Open
ewels opened this issue May 19, 2019 · 1 comment
Open

Failure when post doesn't have an Excerpt #95

ewels opened this issue May 19, 2019 · 1 comment
Labels

Comments

@ewels
Copy link
Owner

ewels commented May 19, 2019

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:

$content = get_the_excerpt();
$image = get_the_post_thumbnail( get_the_ID(), $atts['image_size'] );
$image_src = wp_get_attachment_image_src(get_post_thumbnail_id(), $atts['image_size']);
$image_src = $image_src[0];
$url = get_post_meta(get_the_ID(), 'cptbc_image_url', true);
$url_openblank = get_post_meta(get_the_ID(), 'cptbc_image_url_openblank', true);
$link_text = get_post_meta(get_the_ID(), 'cptbc_image_link_text', true);
$video_url = get_post_meta(get_the_ID(), 'cptbc_video_url', true);
$video_aspect = get_post_meta(get_the_ID(), 'cptbc_video_aspect', true);

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 ewels added the bug label May 19, 2019
@ewels
Copy link
Owner Author

ewels commented May 19, 2019

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant