• Resolved Aslan French

    (@thedonquixotic)


    So I created a custom post type called MM Gallery. I make a couple of galleries as posts and then I want to insert them into blog posts using the shortcode.

    I select the custom post I want to pull information from and I set it using a template file which contains this code:

    <?php
    
    /*
      Template Name: Gallerys
     */
    
    //Variables
    
    $initialCardLoad = 5;
    $loopLazyLoad = 0;
    $gridPostID = get_the_ID();
    
    ?>
    
        <section class="grid-content">
            <div class="gridGallery">
    
    <?php
    // check if the repeater field has rows of data
    if( have_rows('card') ):
    
        // loop through the rows of data
        while ( have_rows('card') ) : the_row();
    $loopLazyLoad++; // iterate on loop each time you loop through
            // display a sub field value inside a card
    
                ?>
    
                <?php
                //VARIABLES//
                $title =  get_sub_field('card_title');
                $childImage = get_sub_field('card_picture');
                $file = get_sub_field('card_video');
                $video = $file['url'];
    
                if($loopLazyLoad > $initialCardLoad):
    
                    if( $childImage ): ?>
                        <div class="grid-item">
                            <a data-fancybox="gallery" data-caption="<?php echo $title ?>" href="<?php
                        echo $childImage['url'];//big one here ?>">
                                <img class="lazy" data-src="<?php echo $childImage['url']; ?>">
                             </a>
                    <?php endif; ?>
    
                    <?php if( $video ): ?>
                        <div class="grid-item">
                            <video class="gallery-video lazy" loop autoplay muted>
                                <source src="<?php echo $video; ?>" type="video/mp4">
                            </video>
                <?php endif; ?>
                    </div> <?php //end of grid item div
    
                else : // Note the combination of the words.
                if( $childImage ): ?>
                    <div class="grid-item">
                    <a data-fancybox="gallery" data-caption="<?php echo $title ?>" href="<?php
                    echo $childImage['url'];//big one here ?>">
                        <img class="" src="<?php echo $childImage['url']; ?>">
                    </a>
                <?php endif; ?>
    
                    <?php if( $video ): ?>
                    <div class="grid-item">
                    <video class="gallery-video" loop autoplay muted>
                        <source src="<?php echo $video; ?>" type="video/mp4">
                    </video>
    
                <?php endif; ?>
                    </div> <!-- end of grid item div -->
    
                   <?php endif; //end of initial card load of loop
    
        endwhile; //end of while statement
    
    else :
     ?> <p>no rowww</p> <?php
        // no rows found
    
    endif;
    
    ?>
    
                    </div>
    
        </section>
    
        <p>right here is the end</p>
    
    <?php

    But I don’t get any rows. It just passes on through to the else statement.

    If I add a post ID to the If and While statement, then it works fine, and spits out exactly what I want. But! it only does this when I give it a specific post ID. It should default to the post that it’s in. But in this case it interprets that as “the post that you are posting into” rather than “the post that you are drawing from”. When I echo out get_the_Post() I get the post number for the blog post NOT for the gallery. So how do I make it hook up to the gallery that’s being inserted? Everything I read online about this plugin would make me think it would do that automatically but for some reason it doesn’t?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem inserting custom post into page. “has_rows” doesn’t appear to work’ is closed to new replies.