• Resolved Jordi

    (@kukat)


    Hi!

    I’m trying to insert values added on Custom Fields on a shortcode with the do_shortcode function, but I don’t know if this is possible.

    My custom fields are displayed like usually: echo get_post_meta($post->ID, ‘bitJanuary’, true);

    I’m using the free version of IChart Plugin. I’m trying to do something like this:

    echo do_shortcode(‘[qcld-ichart label=”JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER” aspectratio=”1″ value=” echo get_post_meta($post->ID, ‘bitJanuary’, true);,CUSTOM_FIELD2,CUSTOM_FIEL3…. CUSTOM_FIELD12,etc….” type=”bar” title=”INVERSIóN” datasetname=”INVERSION” width=”50%” bordercolor=”” pointerstyle=”circle” linestyle=””]’);

    It’s possible? I search for something similar unsuccessfully.

    • This topic was modified 4 years, 7 months ago by Jordi.
    • This topic was modified 4 years, 7 months ago by Jordi.
Viewing 2 replies - 1 through 2 (of 2 total)
  • You wouldn’t use echo inside another echo statement. You can put the value into a variable and then use the variable, or just put the function call directly.
    But, you can also call the shortcode handler function directly, with an array, instead of do_shortcode which has to parse all those parameters to get them into the array format.

    Thread Starter Jordi

    (@kukat)

    Hi! Finally I do this with Chart.js, more simple!!!

    I put the “chart.min.js” using functions.php:

    
    function codigoCharts() {
        wp_enqueue_script( 'chart-js', 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js', array(), true );
    }
    add_action( 'wp_enqueue_scripts', 'codigoCharts');

    I get the data. One for month:

    `$Enero = get_post_meta($post->ID, ‘biteqEnero’, true);
    $Febrero = get_post_meta($post->ID, ‘biteqFebrero’, true);
    $Marzo = get_post_meta($post->ID, ‘biteqMarzo’, true);
    $Abril = get_post_meta($post->ID, ‘biteqAbril’, true);
    $Mayo = get_post_meta($post->ID, ‘biteqMayo’, true);
    $Junio = get_post_meta($post->ID, ‘biteqJunio’, true);
    $Julio = get_post_meta($post->ID, ‘biteqJulio’, true);
    $Agosto = get_post_meta($post->ID, ‘biteqAgosto’, true);
    $Septiembre = get_post_meta($post->ID, ‘biteqSept’, true);
    $Octubre = get_post_meta($post->ID, ‘biteqOct’, true);
    $Noviembre = get_post_meta($post->ID, ‘biteqNov’, true);
    $Diciembre = get_post_meta($post->ID, ‘biteqDic’, true);`

    And I put the data on the “chart.js” javascript code, painting the chart!:

    <canvas id="biteqGrafica" width="400" height="400"></canvas>
    <script>
    var ctx = document.getElementById('biteqGrafica').getContext('2d');
    var myChart = new Chart(ctx, {
        type: 'bar',
        data: {
            labels: ['ENERO', 'FEBRERO', 'MARZO', 'ABRIL', 'MAYO', 'JUNIO', 'JULIO','AGOSTO','SEPTIEMBRE','OCTUBRE','NOVIEMBRE','DICIEMBRE'],
            datasets: [{
                label: 'INVERSIóN',
                data: [<?php echo $Enero ?>, <?php echo $Febrero ?>, <?php echo $Marzo ?>, <?php echo $Abril ?>, <?php echo $Mayo ?>, <?php echo $Junio ?>,<?php echo $Julio ?>,<?php echo $Agosto ?>,<?php echo $Septiembre ?>,<?php echo $Octubre ?>,<?php echo $Noviembre ?>,<?php echo $Diciembre ?>],
                backgroundColor: [
                    'rgba(191, 170, 111, 0.2)',
                       'rgba(191, 170, 111, 0.2)',
                       'rgba(191, 170, 111, 0.2)',
                       'rgba(191, 170, 111, 0.2)',
                       'rgba(191, 170, 111, 0.2)',
                       'rgba(191, 170, 111, 0.2)',
                 'rgba(191, 170, 111, 0.2)',
                       'rgba(191, 170, 111, 0.2)',
                    'rgba(191, 170, 111, 0.2)',
                      'rgba(191, 170, 111, 0.2)',
                      'rgba(191, 170, 111, 0.2)',
                    'rgba(191, 170, 111, 0.2)'
                    
                ],
                borderColor: [
                    'rgba(216, 191, 125, 1)'
                      
                ],
                borderWidth: 0
            }]
        },
        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: true
                    }
                }]
            }
        }
    });
    </script>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Chart with custom parameters on PHP with do_shortcode’ is closed to new replies.