最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - get shortcode value

programmeradmin1浏览0评论

I created a text field in a shortcode for highcharts where we can choose a footer label for the chart. This is the field:

            array(
            'label' => esc_html( 'Footer label' ),
            'description' => esc_html( 'Choose the footer label' ),
            'attr' => 'footer_caption',
            'type' => 'text',
        ),

Until here its all good, the field is created and its saving the value i put in there and its in the database too. Example of the rendered html and what shows up in the database:

<input type="text" class="regular-text" name="footer_caption" id="shortcode-ui-footer_caption-c42" value="test caption" placeholder="">

and:

[the_chart chart="23" footer_caption="test caption"/]

The problem is that i cant get the value of the field. In this chart for eg: test caption

Im not very used to PHP but i tried in a bunch of different ways to retrieve the value on footer_caption but with no luck. Im gonna have to pass that value in another function, so can someone help me out and tell me how i can retrieve the value of footer_caption?

I created a text field in a shortcode for highcharts where we can choose a footer label for the chart. This is the field:

            array(
            'label' => esc_html( 'Footer label' ),
            'description' => esc_html( 'Choose the footer label' ),
            'attr' => 'footer_caption',
            'type' => 'text',
        ),

Until here its all good, the field is created and its saving the value i put in there and its in the database too. Example of the rendered html and what shows up in the database:

<input type="text" class="regular-text" name="footer_caption" id="shortcode-ui-footer_caption-c42" value="test caption" placeholder="">

and:

[the_chart chart="23" footer_caption="test caption"/]

The problem is that i cant get the value of the field. In this chart for eg: test caption

Im not very used to PHP but i tried in a bunch of different ways to retrieve the value on footer_caption but with no luck. Im gonna have to pass that value in another function, so can someone help me out and tell me how i can retrieve the value of footer_caption?

Share Improve this question asked Apr 26, 2017 at 21:56 user117473user117473 215 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2
    add_shortcode('the_chart ', 'high_chart');
        function high_chart($atts, $content = null) {
           //extract the cart and footer_caption value 
            extract(shortcode_atts(array( 'chart' => null, 'footer_caption' => null), $atts));
            /*
               * process your chart and footer_caption value as
               * $chart and $footer_caption and return the process data
             */
            $return_html = 'chart id:'. $chart.'<br/> Footer Caption:'. 
            $footer_caption;
            return $return_html

        }

For reference: https://codex.wordpress/Function_Reference/add_shortcode Hope that you understand!

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论