Support

Account

Home Forums Add-ons Flexible Content Field No content shows after custom post type query within flexible content fields

Solved

No content shows after custom post type query within flexible content fields

  • I am using flexible content fields to create a sidebar of sorts on my site. In one of my fields, I have a query that loops through a custom post type category and shows an image from the most recent post. This all works fine as I have the correct content showing. The problem is, no flexible content fields I create will show on my page after the field with the post loop. I thought the loop was going forever, but I have a button that appears after the loop and is in the same flexible content field that is working correctly. My footer is showing perfectly as well and there isn’t an endless loop or anything. I am at a loss as to what is happening. Its almost like the if statement for the flexible content field that has the custom post loop never ends and doesn’t allow any other flexible content field to be shown after.

    The name of the flexible content field is Subscribe. Within this field, I have a custom post type loop that shows the most recent post and displays an image from that post.

    I’ve also tried this with a standard query through normal posts and I have the same issue. So it doesn’t appear to be a problem with my custom post type loop.

    <!--Sidebar Flexible Content Fields-->
    <?php if( have_rows('sidebar_content') ): ?>
    <div class="width-100 clear">
    
        <!--Loop through the rows of data-->
        <?php while ( have_rows('sidebar_content') ) : the_row(); ?>
    
            <!--Featured Video-->
            <?php if( get_row_layout() == 'featured_video' ): ?>
            <div class="pad-bottom-40 clear">
                <div class="video-box clear grey-bg">
                    <div class="relative">
                        <div class="absolute width-100 text-center play-button">
                            <?php $videoid = get_sub_field('video_id'); ?>
                            <?php $play = get_field('video_play_button', 'option'); ?>
                            <?php echo do_shortcode('[video_lightbox_youtube video_id="'.$videoid.'&rel=0" width="640" height="480" anchor="'.$play.'"]'); ?>
                        </div>
                        <div class="video-thumb">
                            <?php $thumb = get_sub_field('video_thumbnail'); ?>
                            <?php echo do_shortcode('[video_lightbox_youtube video_id="'.$videoid.'&rel=0" width="640" height="480" anchor="'.$thumb.'"]'); ?>
                        </div>
                    </div>
                    <div class="video-title font-18 font-weight-600 pad-top-5">
                        <?php $videotitle = get_sub_field('video_title'); ?>
                        <?php echo do_shortcode('[video_lightbox_youtube video_id="'.$videoid.'&rel=0" width="640" height="480" anchor="'.$videotitle.'"]'); ?>
                    </div>
                </div>
            </div>
            <?php endif; ?>
            <!--End Featured Video-->
        
            <!--Avertisement-->
            <?php if( get_row_layout() == 'advertisement' ): ?>
            <div class="pad-bottom-40 clear">
                <div class="font-10 text-upper text-center font-med-grey pad-bottom-5">Advertisement</div>
                <a href="<?php the_sub_field('advertisement_link'); ?>" target="_blank">
                    <?php $adimage = get_sub_field('advertisement_image'); ?>
                    <img src="<?php echo $adimage['url']; ?>" class="width-100" alt="<?php echo $adimage['title'] ?>" title="<?php echo $adimage['title'] ?>" />
                </a>
            </div>
            <?php endif; ?>
            <!--End Advertisement-->
        
            <!--Newsletters-->
            <?php if( get_row_layout() == 'newsletters' ): ?>
            <div class="pad-bottom-40 clear">
                <div class="black-bg width-100 clear font-white pad-top-15 pad-bottom-15">
                    <div class="clear font-18 pad-bottom-10 pad-left-20 pad-right-20 font-weight-600 black-border">
                        <?php the_sub_field('newsletters_headline'); ?>
                    </div>
                    <div class="clear pad-top-20 text-center pad-bottom-20">
                        <a href="<?php the_sub_field('newsletters_button_link'); ?>" class="white-btn">
                            <?php the_sub_field('newsletters_button_text'); ?>
                        </a>
                    </div>
                </div>
            </div>
            <?php endif; ?>
            <!--End Newsletters-->
        
            <!--Subscribe-->
            <?php if( get_row_layout() == 'subscribe' ): ?>
            <div class="pad-bottom-40 clear">
                <div class="grey-bg width-100 clear pad-top-15 pad-bottom-15">
                    <div class="clear font-18 pad-bottom-10 pad-left-20 pad-right-20 font-weight-600 red-border">
                        <?php the_sub_field('subscribe_headline'); ?>
                    </div>
                    
                    <?php
    
                    // Your arguments    
                    $args = array(
                        'post_type' => 'printed-pages',
                        'posts_per_page' => 1,
                        'printed-pages-category' => 'issue',
                    );
    
                    // Let's get the query, using WP_Query
                    $loop = new WP_Query($args);
    
                    // Check if there are posts for our query
                    if ( $loop->have_posts() ) : ?> 
    
                        <?php 
                        // Get looping    
                        while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
                        <!--Content Here-->
                        <div class="clear">                        
                            <?php if( have_rows('printed_page_content') ): ?>
                            <div class="width-100 clear">
    
                                <!--Loop through the rows of data-->
                                <?php while ( have_rows('printed_page_content') ) : the_row(); ?>
    
                                    <!--Subscribe-->
                                    <?php if( get_row_layout() == 'cover_image' ): ?>
                                    <div class="text-center pad-top-20">
                                        <img src="<?php the_sub_field('cover_image'); ?>" class="cover-sidebar" />
                                    </div>
                                    <?php endif; ?>
                                    <!--End Subscribe-->
    
                                 <?php endwhile; ?>
                                <!--End loop through the rows of data-->
    
                            </div>
                            <?php endif; ?>
                        </div>
                        <!--End Content Here-->
    
                        <?php endwhile; ?>
    
                    <?php endif; ?>
                    <?php wp_reset_postdata(); ?>
                    
                    <div class="clear pad-top-20 text-center pad-bottom-20">
                        <a href="<?php the_sub_field('subscribe_link'); ?>" class="red-btn">
                            <?php the_sub_field('subscribe_button_text'); ?>
                        </a>
                    </div>
                </div>
            </div>
            <?php endif; ?>        
            <!--End Subscribe-->
        
        <?php endwhile; ?>
        <!--End loop through the rows of data-->
        
    </div>
    <?php endif; ?>
    <!--End Sidebar Flexible Content Fields-->
  • Hi @billcommexis

    Could you please provide the post ID to the have_rows() function like the following?

    have_rows('sidebar_content', 99)

    And:

    have_rows('printed_page_content', 99)

    Where ’99’ is the post/page ID where the custom fields are located (you can dynamically get the ID if you want).

    If that doesn’t work, could you please try to debug the ‘printed_page_content’ field like bellow?

    var_dump( get_field('printed_page_content', 99) );

    Thanks 🙂

  • Setting the post id in the flexible content fields totally worked. Thank you so much for the help. I was going crazy yesterday trying to figure out why it wasn’t working. Thanks again!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘No content shows after custom post type query within flexible content fields’ is closed to new replies.