mardi 24 mars 2015

Insert a custom field into a shortcode and use it in post(s)


I would like to insert a custom field into a shortcode and use it in post(s). I want the shortcode to be with parameters. I tried to solve this problem but it displays the "Array" word instead of the value of the custom field:


function get_my_custom_field($atts) { global $post; return get_post_meta($post->ID, $field, true); } add_shortcode('insert-custom-field', 'get_my_custom_field');


The shortcode present in the post: [insert-custom-field field="price"]





Aucun commentaire:

Enregistrer un commentaire