2

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');
Community
  • 1
  • 1
kenwebart
  • 51
  • 2
  • 9
  • Are you rewriting the *gallery* shortcode? Is `get_gallery_ids` the callback of your shortcode? I suppose you'll have to dig into WP [`shortcodes.php`](http://core.trac.wordpress.org/browser/tags/3.6/wp-includes/shortcodes.php) file and tweak some of its functions to your own. – brasofilo Sep 20 '13 at 13:25
  • Thank you, and yes, I'm rewriting the gallery shortcode. I went through the code, but WordPress saves their return in §output . = value. ... $output . = "
    " ... return $output; Is there no better way?
    – kenwebart Sep 20 '13 at 15:35
  • Research at [wordpress.se], check this results: http://wordpress.stackexchange.com/search?tab=votes&q=gallery%20shortcode%20is%3aq – brasofilo Sep 20 '13 at 16:06
  • It helped. Thank you! I researched and somebody had a similar problem and the answer was solved by a link back to stackoverflow. Funny! This helped me: http://stackoverflow.com/questions/14277794/wordpress-3-5-own-gallery-with-included-images-doesnt-work – kenwebart Sep 24 '13 at 15:38

1 Answers1

0

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.

theode
  • 300
  • 1
  • 7