Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Load content including data from a content template

  • Is it possible to insert the single portfolio content into that modal?

    I don’t think so, as the Content Template will hijack the single posts content-single.php – GP is not going to load that outside of the single loop.

    I think you’re better off just incorporating the slider into your current template.
    Your issue with that is the shortcode is calling: $images = get_field('gallery');
    And its not going to find the fields, you will need to pass the current post ID to get them

  • Hmmm ok, I see. Seems like I am gonna have problems with this one, lol.

    I have modified the slider shortcode code:

    //Portfolio slider shortcode
    function portfolio_slider_shortcode() {
        // Log a message to indicate that the shortcode function is being executed
        error_log('Portfolio slider shortcode called');
    
        // Get the ID of the current post
        $post_id = get_the_ID();
    
        // Get the 'gallery' field for the current post
        $images = get_field('gallery', $post_id);
        
        ob_start();
        if ($images): ?>
            <section class="splide" aria-label="Splide Basic HTML Example">
                <div class="splide__track">
                    <ul class="splide__list">
                        <?php foreach ($images as $image): ?>
                            <li class="splide__slide">
                                <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
                            </li>
                        <?php endforeach; ?>
                    </ul>
                </div>
        <?php endif;
        return ob_get_clean();
    }
    add_shortcode('portfolio_slider', 'portfolio_slider_shortcode');
    

    The code is executed but the slider is still not rendered. It renders on the single post still. Am I missing something?

    Note: The modal opening happens on the archive. Could that be an issue?

  • Theres 2 issues I think:

    1. this: $post_id = get_the_ID(); won’t get the ID of the post you want as its not being called from within the loop.

    In your fetch_custom_post_content() function, you do get the ID here:

    $post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0;`

    2. The shortcode is using Object buffering, and I have no idea the issues that may cause when being returned from an Ajax call.

    Try outputting the ACF Field values and slider HTML directly inside the fetch_custom_post_content()

  • Yeah, I managed to get the slider images in but I think the problem is the shortcode rendering as you mentioned! I am gonna leave it at that and revisit another time, I had high hopes for it!

    Thanks again.

  • Keep up the high hopes 🙂

Viewing 5 posts - 17 through 21 (of 21 total)
  • You must be logged in to reply to this topic.