Getting custom field value to functions.php and displaying in on the shortcode
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.
php wordpress custom-fields wordpress-shortcode
add a comment |
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.
php wordpress custom-fields wordpress-shortcode
add a comment |
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.
php wordpress custom-fields wordpress-shortcode
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.
php wordpress custom-fields wordpress-shortcode
php wordpress custom-fields wordpress-shortcode
asked Nov 15 '18 at 19:27
t3xt3x
174
174
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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');
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.
– t3x
Nov 15 '18 at 20:31
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.
– amedv
Nov 15 '18 at 20:57
Great. Many thanks. It worked just the way I wanted. I really appreciate your help
– t3x
Nov 15 '18 at 21:27
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326658%2fgetting-custom-field-value-to-functions-php-and-displaying-in-on-the-shortcode%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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');
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.
– t3x
Nov 15 '18 at 20:31
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.
– amedv
Nov 15 '18 at 20:57
Great. Many thanks. It worked just the way I wanted. I really appreciate your help
– t3x
Nov 15 '18 at 21:27
add a comment |
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');
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.
– t3x
Nov 15 '18 at 20:31
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.
– amedv
Nov 15 '18 at 20:57
Great. Many thanks. It worked just the way I wanted. I really appreciate your help
– t3x
Nov 15 '18 at 21:27
add a comment |
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');
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');
edited Nov 15 '18 at 20:52
answered Nov 15 '18 at 20:15
amedvamedv
19712
19712
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.
– t3x
Nov 15 '18 at 20:31
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.
– amedv
Nov 15 '18 at 20:57
Great. Many thanks. It worked just the way I wanted. I really appreciate your help
– t3x
Nov 15 '18 at 21:27
add a comment |
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.
– t3x
Nov 15 '18 at 20:31
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.
– amedv
Nov 15 '18 at 20:57
Great. Many thanks. It worked just the way I wanted. I really appreciate your help
– t3x
Nov 15 '18 at 21:27
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.
– t3x
Nov 15 '18 at 20:31
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.
– t3x
Nov 15 '18 at 20:31
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.
– amedv
Nov 15 '18 at 20:57
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.
– amedv
Nov 15 '18 at 20:57
Great. Many thanks. It worked just the way I wanted. I really appreciate your help
– t3x
Nov 15 '18 at 21:27
Great. Many thanks. It worked just the way I wanted. I really appreciate your help
– t3x
Nov 15 '18 at 21:27
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326658%2fgetting-custom-field-value-to-functions-php-and-displaying-in-on-the-shortcode%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown