This is how $attr is created:

$attr = shortcode_atts( array(
        'chart' => null,
        'footer_caption' => null,
    ), $attr, $shortcode_tag );

This is the print_r of $attr in this post ( that has 3 graphs, if it had more or less the array dimenson would change):

    Array
(
    [chart] => 23
    [footer_caption] => label 1
)

    Array
(
    [chart] => 22
    [footer_caption] => label 2
)

    Array
(
    [chart] => 24
    [footer_caption] => label 3
)

Then i need to pass $attr['footer_caption'] to a JS file where the highcharts plugin settings are being defined like this:

    <script>
    var captionLabel = "<?php echo $attr[ 'footer_caption' ]; ?>"
    </script>

And this is the setting in the js file where i pass the $attr['footer_caption'] strings through captionLabel:

   Highcharts.setOptions({
  credits: {
          enabled: false
  },
  chart: {
          type: 'column',
          events: {
              load: function () {
                var label = this.renderer.label(captionLabel)
                  .css({
                      width: '400px',
                      fontSize: '9px'
                  })
                  .attr({
                      'r': 2,
                      'padding': 5
                  })
                  .add();

                  label.align(Highcharts.extend(label.getBBox(), {
                      align: 'center',
                      x: 0, // offset
                      verticalAlign: 'bottom',
                      y: 20 // offset
                  }), null, 'spacingBox');

              }
          },
          marginBottom: 120
      },
      legend: {
        align: 'center',
        verticalAlign: 'bottom',
        y: -30
    },
    decimalPoint: ',',
    thousandsSep: '.'
});

But it only outputs the last footer caption to every chart (in this case ‘label 3’. I was thinking it needs a foreach or a for loop but i dont know how to do it in this case cause i dont see the indexes. This is what $attr['footer_caption'] outputs:

[02-May-2017 15:31:17 UTC] label 1
[02-May-2017 15:31:18 UTC] label 2
[02-May-2017 15:31:19 UTC] label 3

Can anyone point me in the right direction? I know this question is probably confusing.

Read more here: How can i iterate through this shortcode array?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: