Reputation: 1051
I am creating a series of shortcodes that link to pages on a custom post type called heroes
. I was wondering how I can link the info in my shortcode to that custom post type's post so I can pull in custom field data into the shortcode to use.
Here is the shortcode I am using
add_shortcode('illidan', 'illidan');
function illidan($args) {
$default = array('icon' => 'true');
$args = wp_parse_args($args, $default);
$herotip = '';
if ($args['icon']) {
$herotip.= '<img src="http://stormable.com/img/heroes/illidan/illidan-ab1.png">';
}
$herotip.= '<a href="http://stormable.com/heroes/illidan/">Illidan</a>
This is where I would like to pull in custom field data from the post illidan
For example <?php echo get_post_meta($post->ID, "health-lvl1", true); ?>
';
return $herotip;
}
So under the link I would like to be able to pull in data that I have in custom fields from the post Illidan
under the custom post type heroes
although I'm not sure how to link it to that page.
Upvotes: 0
Views: 2507
Reputation: 9782
This return the custom field value from the post meta
// returns the value of health-gain
$health_gain = get_post_meta( 11, 'health-gain', true);
$herotip.= '<a href="http://stormable.com/heroes/illidan/">Illidan</a>
This is where I would like to pull in custom field data from the post illidan
For example '. $health_gain;
take a look on this link get_post_meta(), Implement it into your shortcode function where ever you want.
I Suggest you to take a look on this article http://wp.smashingmagazine.com/2012/05/01/wordpress-shortcodes-complete-guide/, tells you the more robust and right way to create a shortcode.
Upvotes: 0