Support

Account

Home Forums ACF PRO Get field block in footer

Solving

Get field block in footer

  • Hello

    I’m tring to setting slick slider with acf in a custom block.

    I wish user can change the opacity and the slider speed.

    In my footer I added slick jquery:

    Before I tried to call $imageSliderOpacity with a get post ID :

    $postID = get_the_ID();
    $elementsFond = get_field('content-header', $postID);
    $visuels = $elementsFond['visuel'];
    $imageSliderOpacity = $visuels['slider_opacity'];
    $imageSliderSpeed = $visuels['slider_speed'];
    
    <script>
    	jQuery(document).ready(function($){
    		$('.slider').slick({
    		slidesToShow: 1,
    		slidesToScroll: 1,
    		dots: true,
    		arrows: false,
    		focusOnSelect: true,
    		fade: true,
    		autoplay: true
    		});	
    
    		var opacitySlider = '<?php echo $imageSliderOpacity ?>';
    		$('.slick-track').css( "opacity", opacitySlider);
    
    		
    	});
    </script>

    I tried to echo $postID it’s working but my value from my field $imageSliderOpacity return nothing.

    Does anyone knows how to make it work ?

  • are you sure that get_the_ID() is returning the correct post ID? Just because it is returning something does not mean it’s correct.

  • Thanks for the answer 🙂

    Yes it is, I just checked

    Just move my fields into another group but same problem.
    This is the new code in footer.php:

    <?php $postID = get_the_ID();
    $parametres = get_field('parametres', $postID);
    $imageSliderOpacity = $parametres['opacity']; 
    $imageSliderSpeed = $parametres['slider_speed'];
    echo $imageSliderOpacity; // returning nothing
    echo $postID; // returning 260 it's the correct post ID
    ?>
    <script>
    	jQuery(document).ready(function($){
    		$('.slider').slick({
    		slidesToShow: 1,
    		slidesToScroll: 1,
    		dots: true,
    		arrows: false,
    		focusOnSelect: true,
    		fade: true,
    		autoplay: true
    		});	
    
    		var opacitySlider = '<?php echo $imageSliderOpacity ?>';
    		$('.slick-track').css( "opacity", opacitySlider);
    
    		
    	});
    
    	
    </script>

    In my template block the same values (without the postID in the get_field) are working, but not in the footer.
    Can we use may be the key block in the get_field rather than post id, if yes how ?

  • You keep saying block… do you mean a gutenberg block? If this is the case then you need to get the content and the fields are in there somehow. Blocks do not store content in post meta like standard ACF fields and you can not get them using get_field(), or at least that’s my understanding of it because I do not develop for guberbug. If this is the case then you need to look in a different direction. There are topics on this forum about getting data stored in blocks.

  • Thank you

    Yes it’s an ACF Gutenberg block, so that’s why it doesn’t work 🙂

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.