I tried to add the add_filter( ‘should_load_separate_core_block_assets’, ‘__return_true’ ); in function.php but it’s breaking the website
Oh interesting,
Could you just give me the complete code with the add filter with my example ?
Hi, thanks for the answer 🙂
Yes that’s I tried to do
But the problem, is my content is not an ACF field it just simple content from gutenberg
I made a easy function in JQuery to list all the title in the page, that’s working on the console but I don’t now how to displey them in the select field from ACF
I thought doing something like this
function acf_load_titles_field_choices( $field ) {
wp_enqueue_script('summary', get_template_directory_uri() . '/inc/js/summary.js', array(), '1.0.0', 'true' );
}
add_filter('acf/load_field/id=field_6218bb3d7551a', 'acf_load_titles_field_choices');
But of course it doesn’t work
Thank you, I will try another approch 🙂
Thank you
Yes it’s an ACF Gutenberg block, so that’s why it doesn’t work 🙂
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 ?
Solved,
I had a bug, by desactivate and activate ACF, it’s working well now.
thanks 🙂 it’s working
the final code:
while ( have_rows('reseaux-sociaux', 'option') ) : the_row();
echo '<ul>';
foreach ($fields as $sub_field) {
$field = get_sub_field_object($sub_field);
$lien = $field['value'];
$image = $field['label'];
if ($field['value']){
echo '<li><a href="'.$lien.'" target="_blank"><img src="'.get_stylesheet_directory_uri().' /imgs/icons/social/rondes/pleines/' . $image. '-icon.svg"></a></li>';
}
}
echo '</ul>';
endwhile;
Hello John
Have you tested something to resolve it ?
So I have some difficulties with ajax. With a developper friend, we did like this and it’s working.
So if someone have the same problem, we did it like this:
I made a php file “parametres-template-css.php” wich calling acf fields and use:
<?php
if( have_rows('repeater', 'option') ):
while( have_rows('repeater', 'option')): the_row();
$FieldColor = get_sub_field('color');
endwhile;
endif;
the first problem was I used the_sub_field and not get_subfield
I made my css-php “styles-css.php” file including “parametres-template-css.php” like this:
<?php require( 'parametres-template-css.php'); ?>
<?php /* ---------------- TITLE ---------------- */ ?>
h1{ color: <?php echo $h1titleColor ; ?>;}
and I included this file in my headers
<style><?php include("inc/template/css-template/styles-css.php"); ?></style>
Thanks but it’s displaying all the fields in reseaux-sociaux even if they are empty
Oh thanks,
So the inline is not the solution in my opinion…
I may add the script with admin-ajax
it’s not really about ACF but have you an exemple for the ajax way ?
hi thank you for your answer 🙂
Actually I’m making a generic personnal template with customization from the backend; something like in the premium themes.
So I made a “theme apearance options page”. I added fields like “h1 title” as repeater and “colors, fonts…” as subfields.
I made a specific css for my “customization theme” but to display the ACF fields I’m using a php file enqueued as stylesheet.
When I’m enter the value like “$color =’#fff'” and echo it on the css tag it’s working.
So I think my problem is ACF doesn’t knows which fields i’m calling from this file and I need create a function with an add_action. But may be i’m wrong …
But I don’t know how resolve it
thanks it’s working 🙂
Thank you, but it’s not working
<?php
$category = get_the_category();
$name= $category[0]->name;
$slug= $category[0]->slug;
$id = $category[0]->cat_ID;
$sous_titre = get_field('sous_titre_categorie', $category );
?>
<div class="block-site title-cat" id="block-Apropos">
<h1><?php echo $name ?><br/>
<span> <?php echo $sous_titre ?></span>
</h1>
</div>
thanks 🙂
and to display it, we use:
<?php
$category = get_the_category();
$catID= $category->ID;
get_field('subtitle_cat', $catID ) ?>
?
be cause it’s not working…
thank you for your answer :),
But it doesn’t return what I wish. I just edit my code to explain precisly; may be it will be cleaner:
<?php if (have_rows('formule')) {
while (have_rows('formule')) {
the_row();
the_sub_field('prix_de_la_formule');
echo '<br />';
$value = get_sub_field('prix_de_la_formule');
$count = count($value); // count number of values in the page
if ($count = 1) {
echo $value; // get the value
}
elseif ($count > 1) {
echo 'from .$lowestValue. to .$hightestValue' ; // get "the lowest value"
}
} // end while have rows
} // end if have_rows ?>
It’s not working of course.
With this one “$value” return a loop repeating the only one value, it’s not what I want.
For lowest and hightest value, it’s not the same prices all the time (depends formula), so I wish make something picking up the values (in table mabe be ?) and compare all of them to display lowest and hightest from the results
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.