Display custom post meta using a shortocde on WordPress

399 Views Asked by At

I have searched high and low and none of the solutions I have found have worked for me.

I have created a custom post type call Testimonials and I have created two new custom post fields called testimonial-author and testimonial-company (these are both stored in the postmeta database table).

I would like to use a shortcode to display these on the post page along with the testimonial text.

Can anyone please help me with the code?

add_shortcode('testimonial_author', 'testauth');

function testauth($atts) {
    global $post;

    return get_post_meta($post->ID,'testimonial-author',true);

}
1

There are 1 best solutions below

0
On

I used this code instead and it works now:

//Testimonial Author
function test_auth_shortcode($attr) {
    global $post;
    return get_post_meta($post->ID,'testimonial-author', true);
}
add_shortcode('test_auth', 'test_auth_shortcode');