Support

Account

Home Forums ACF PRO Flexible Content on options page not saving/displaying.

Solved

Flexible Content on options page not saving/displaying.

  • Hi everyone!

    I’ve been using ACF and ACF Pro for a few years now. I’ve run into a problem and have exhausted pretty much every possible solution over the last couple of days. I’m looking for any help I can get!

    I’m using flexible content on the options page to show on the homepage as a slider. This works perfectly on my local install but doesn’t work at all on the live site for the client (the logo from the options page does show).

    Here’s a screenshot of the setup and the code I use to show the slider.

    
    
        // check if the flexible content field has rows of data
        if( have_rows('ffc', 'option') ):
            
            echo '<div class="flexslider"><ul class="slides">';
    
             // loop through the rows of data
            while ( have_rows('ffc', 'option') ) : the_row();
    
                // check current row layout
                if( get_row_layout() == "content" ): 
                    
                    echo '<li class="slide">';
    
                            $titleText = '<h3 class="title-text">'.get_sub_field('title').'</h3>';
    
                            $leftText = get_sub_field('ljt');
                            $rightText = get_sub_field('rjt');
                            $centeredText = get_sub_field('cjt');
    
                        if(get_sub_field('style') == "tol")
                        {
                            //...
                            echo "<div class=\"text left\">$titleText $leftText</div>";
    
                        } elseif(get_sub_field('style') == "tor")
                        {
                            //...
                            echo "<div class=\"text right\">$titleText $rightText</div>";
    
                        } elseif(get_sub_field('style') == "tc")
    
                        {
                            //...
                            echo "<div class=\"text center\">$titleText $centeredText</div>";
    
                        }
                        
                        if(get_sub_field('image'))
                        {   
    
                            $image = wp_get_attachment_image_src(get_sub_field('image'), 'feature-slider');?>
                            <img class="slide-image" src="<?php echo $image[0]; ?>" alt="<?php echo get_the_title(get_field('image'))?>">
                        <?php }
                            echo "</li>";
                        endif;
    
                endwhile;
                echo '</ul></div>';
    
                else :
    
                    // no layouts found
    
        endif;
    

    I used this to debug:

    
    echo '<pre>';
        print_r( get_field('ffc', 'option') );
    echo '</pre>';
    die; 

    and received this in return on the live site:

    Array ( [0] => content [1] => content )

    and on the local site:

    Array ( [0] => Array ( [acf_fc_layout] => content [image] => 16576 [title] =>
    Title of this slide
      [style] => tol [ljt] =>
    Nunc quis elit nec metus dignissim feugiat sit amet ut erat.
      [rjt] =>  [cjt] =>  )  [1] => Array ( [acf_fc_layout] => content [image] => 16577 [title] =>
    Why not try this?
      [style] => tor [ljt] =>  [rjt] =>
    Nulla tincidunt leo leo, quis lobortis odio mattis in. In bibendum mi metus, hendrerit gravida libero pulvinar finibus.
      [cjt] =>  )  )

    Any help is appreciated!

  • I don’t know if it would cause a complete failure but in your image you use get_field(‘image’) instead of get_sub_field(‘image’).

    Otherwise at a first glance that looks like it’s all correct…

    Edit: Do double check that your image field especially, but that all your other fields are definitely outputting in the correct format. If your image field is outputting as ID locally but as an Array on live it’s an easy thing to miss but will mess everything else up

  • Thanks for the image get_sub_field change!

    I looked through everything else and it seems in order. It’s really bugging me as I’ve focused a few mornings on just this.

    Edit: Further making this more strange is that I just clicked a post and a page and the slider shows but on the homepage and archive page it doesn’t!

    Edit 2: I thought back about this after the first edit and I found the problem. I had code in the functions.php of my theme that was conflicting with ACF.

    Here is the code in question that I removed and then everything started working fine.

    
         // Adding custom post types to homepage
        add_filter( 'pre_get_posts', 'my_get_posts' );
            function my_get_posts( $query ) {
                if ( is_home() && false == $query->query_vars['suppress_filters'] )
                $query->set( 'post_type', array( 'post', 'quote', 'attachment', 'status', 'audio', 'chat', 'video' ) );
                return $query;
            }
    
         //CPT on Archives
        function add_custom_types_to_archives( $query ) {
            if (! is_post_type_archive() ) {
                if( is_archive() && empty( $query->query_vars['suppress_filters'] ) ) {
    
                    /*// Get all your post types
                    $post_types = get_post_types();*/
                    
                    $post_types = array('post','movie');
    
                    $query->set( 'post_type', $post_types );
                    return $query;
                }
            }
        }
        add_filter( 'pre_get_posts', 'add_custom_types_to_archives' );
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Flexible Content on options page not saving/displaying.’ is closed to new replies.