0

Maybe someone would be able to help me with the issue I have as I'm stuck with no ideas.

I have a shortcode on my site that is responsible for displaying photosets directly from Flickr (via external plugin).

The code generated by the plugin is the following: [justified_image_grid preset=c1 flickr_user=USERID flickr_photoset=PHOTOSETID]

My blog posts displays various photosets from Flickr. I'd like to avoid having to edit shortcode each and every time to update the shortcode code with the proper photoset ID so I decided to use custom field (Key = FlicktPhotoset, Value = Photoset ID) and add function to functions.php that would create my shortcode which would include original shortcode with the value from custom field.

Code in functions.php is the following:

function flickr_shortcode() {
    echo do_shortcode('[justified_image_grid preset=c1 flickr_user=USERNAME flickr_photoset=PHOTOID]');
}
function flickr_shortcodes_init() {
    add_shortcode('flickr', 'flickr_shortcode');
}
add_action('init', 'flickr_shortcodes_init');

What I'm stuck at is how to pass shortcode value into this code to automatically fetch PHOTOID from the custom field value.

1 Answer 1

1

Something like this:

function flickr_shortcode() {
    $FlicktPhotoset = get_post_custom_values("FlicktPhotoset");       
    echo do_shortcode('[justified_image_grid preset=c1 flickr_user=USERNAME flickr_photoset='.$FlicktPhotoset[0].']');
}
function flickr_shortcodes_init() {
    add_shortcode('flickr', 'flickr_shortcode');
}
add_action('init', 'flickr_shortcodes_init');
Sign up to request clarification or add additional context in comments.

3 Comments

Nope, unfortunately something like this doesn't work. While I'm using this code, Flickr API returns information that the photoset of this ID doesn't exist. When I replace it with ID number (without getting custom field value) it's working fine. It seems to me that somehow Function cannot get the custom field value.
Sorry, I think this function return array, I modified code, try new one, please. Also, it's depends where you run your shortcode, if you use it outside of loop — you also have to pass post_ID as second parameter.
Great. Many thanks. It worked just the way I wanted. I really appreciate your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.