这是各国插件中的代码,但我不知道如何以简短的形式编写此代码,
function save_details( $post_id ) {
global $post;
$post_vars = shortcode_atts( array(
'country_code' => '',
'country_list' => '',
'flags' => '',
'country_details' => '',
'country_currency' => '',
'currency_symbol' => '',
'currency_html' => '',
'currency_code' => '',
'city_list' => ''
), $_POST );
有人能告诉我我应该写一些简短的代码,以便在一个页面上获取所有国家的名字吗?
答案 0 :(得分:0)
您可以像这样重写您的功能
add_shortcode('save_details', function( $atts ) {
global $post;
$post_vars = array(
'country_code' => '',
'country_list' => '',
'flags' => '',
'country_details' => '',
'country_currency' => '',
'currency_symbol' => '',
'currency_html' => '',
'currency_code' => '',
'city_list' => ''
);
extract( shortcode_atts( $post_vars, $atts ) );
// country_code is now available like so $country_code
// return data after your done
});
并像这样访问
//all of your attributes can be used inside the sq brackets
[save_details] and [save_details country_code = "" country_list = ""]