jQuery script in WordPress loop

I am trying to loop a jquery script so that it affects all the post loaded. The script has a php variable in it so put it in the loop and thought that this was enough but instead it’s only sort of applied only to the first post.
Here’s my php for the script

<?php $valutazione0 = simple_fields_get_post_value(get_the_id(), array(3, 1), true);?>

<div class="postbackrotator" id="rotator-<?php the_ID(); ?>" style="height:43px;width:43px"><canvas height="43" width="43" id="my-canvas"></canvas></div>

Here I’m getting a value from Simple Fields, it works fine in single.php for example.
Below I have the script with the variable

Read More
<script type="text/javascript">
    jQuery(document).ready(function(){
     $('#rotator-<?php the_ID(); ?>').rotator({
        starting: 0,
        ending: <?php echo($valutazione0)?>,
        lineWidth: 1.5,
        fontSize: '13px',
        radius: 21
     });
    });
</script>

Everything is in the loop that loads the posts but it’s not working. What am I doing wrong here?

What is the proper way to apply a script to all the posts in the loop?

Related posts

Leave a Reply

1 comment

  1. <script type="text/javascript">
            jQuery(document).ready(function(){
     $('#rotator').rotator({
        starting: 0,
        ending: <?php echo $valutazione0?>,
        lineWidth: 1.5,
        fontSize: '13px',
        radius: 21
    })
    })
        </script>
    

    Try this