WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Meta box value shortcode (3 posts)

  1. jasonsweb
    Member
    Posted 1 year ago #

    Hi,

    I'm trying to achieve the following:
    A shortcode of my Custom Post Type "Testimonials". In the WordPress editor the user enters the ID of the testimonial post (like [testimonial id="74"]) and then the shortcode displays the correct testimonial.

    In my shortcode file I've got the following code to get the title and content of the testimonial:

    $testimonial_id = get_post($id);
    $testimonial_title = $testimonial_id->post_title;
    $testimonial_content = $testimonial_id->post_content;

    This works perfect. But I've also got 1 meta box value I would like to get. But how do I retrieve this value?
    I've tried this:
    get_post_meta($testimonial_id, 'testimonial_company', true);

    Unfortunately this doesn't work.

    Does someone has an idea of what I'm doing wrong??
    Thanks in advance!

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    try:

    get_post_meta($id, 'testimonial_company', true);

    or:

    get_post_meta($testimonial_id->ID, 'testimonial_company', true);
  3. jasonsweb
    Member
    Posted 1 year ago #

    Awesome! Thanks a lot!

Topic Closed

This topic has been closed to new replies.

About this Topic