Pergunta

Is it possible to use variables from shortcode_atts in another function? Here is my idea:

Posting

[gallery ids="1,2,3,...n"]

Function get_gallery_ids()

//get the gallery-ID's from post
function get_gallery_ids($atts) {
extract(shortcode_atts(array(
'ids'   => ''
), $atts));
return $ids;
}

Function explode_ids()

//example function with ids
function explode_ids($ids) {
$ids = explode(',' $ids);
}

How do I implement it? The return just echos.

Update

The code above is a part of my own new gallery_shortcode.

remove_shortcode('gallery', 'gallery_shortcode');
add_shortcode('gallery', 'get_gallery_ids');

Nenhuma solução correta

Outras dicas

I have an Idea:

I use examples from the WordPress Codex http://codex.wordpress.org/Shortcode_API

function bartag_func( $atts ) {
    global $post;   // this is new
    extract( shortcode_atts( array(
    'foo' => 'something',
    'bar' => 'something else',
), $atts ) );
    update_post_meta($post->ID, "gallery_used_atts", $atts); // this is new

return "foo = {$foo}";
}
add_shortcode( 'bartag', 'bartag_func' );

now you are able to get the $atts you are using on a specific post or page by

$att_values = get_post_meta( $post_id, "gallery_used_atts", true );

and then you can use them for whatever you want.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top