Output Custom Field value to shortcode

admin2025-01-07  3

I am trying to automate a whole bulk of my pages and one of the shortcodes I have created is to output the NextGen Gallery Tags by using the page custom fields that each page has a unique id. This id is actually tagged into certain galleries which I want to output on the page.

For those unfamiliar with NextGen Gallery tags shortcode. Please visit this link.

Each page has a custom field "gallery_id" which I input a unique tagged id everytime I create a page. I want every page to have the same template but pull different information depending on the custom fields.

This is my current shortcode, but at this stage, it is only outputting as text, but not as a shortcode. Does anyone know how to output this as a shortcode?

// Grab ID Custom Field [gallery_display] function lilap_gid( ){ $gid = get_post_meta(get_the_ID(), 'gallery_id', TRUE); return do_shortcode( '[ngg_images tag_ids="'. $gid .'"]'); } add_shortcode( 'gallery_display', 'lilap_gid' );

I am trying to automate a whole bulk of my pages and one of the shortcodes I have created is to output the NextGen Gallery Tags by using the page custom fields that each page has a unique id. This id is actually tagged into certain galleries which I want to output on the page.

For those unfamiliar with NextGen Gallery tags shortcode. Please visit this link.

Each page has a custom field "gallery_id" which I input a unique tagged id everytime I create a page. I want every page to have the same template but pull different information depending on the custom fields.

This is my current shortcode, but at this stage, it is only outputting as text, but not as a shortcode. Does anyone know how to output this as a shortcode?

// Grab ID Custom Field [gallery_display] function lilap_gid( ){ $gid = get_post_meta(get_the_ID(), 'gallery_id', TRUE); return do_shortcode( '[ngg_images tag_ids="'. $gid .'"]'); } add_shortcode( 'gallery_display', 'lilap_gid' );

Share Improve this question edited Nov 21, 2016 at 15:34 Lilap asked Nov 21, 2016 at 15:26 LilapLilap 291 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Depending on the ngg_images shortcode, you maybe need to echo the do_shortcode function.

You can try

function lilap_gid($atts, $content = ""){
$gid = get_post_meta(get_the_ID(), 'gallery_id', TRUE);
ob_start();
echo do_shortcode( '[ngg_images tag_ids="'. $gid .'"]');
$content = ob_get_clean();
return $content;
}
add_shortcode( 'gallery_display', 'lilap_gid' );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736260604a677.html

最新回复(0)