Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Neo WhiteRabbit

    (@longnguyen89)

    Hi,

    Thanks for reaching out.

    Did you add the code that outputs the field value to the post template in the theme folder?

    You can also try to use this code to re-check this issue

    echo rwmb_meta( 'testing_data', '', 123 );

    where 123 is the post ID. Read more on the documentation https://docs.metabox.io/functions/rwmb-meta/

    Thread Starter ace0930

    (@ace0930)

    Hi, thanks for responding. What if I want to display the custom field value from a specific post type instead of one post?

    Assume the slug of the custom post type is ‘apple’ and the custom field ID is ‘testing_data’, I’ve tried this code but it’s not working.

    <p>
        <strong>Display:</strong> <?php rwmb_get_value( 'testing_data', ['post_type' => 'apple'] ) ?>
    </p>
    Plugin Support Neo WhiteRabbit

    (@longnguyen89)

    Hi,

    The field ID and value are associated with the post type by the post ID, so no need to define the post type in the helper function. You can just pass the post ID to the third parameter to display the field value.

    <p>
        <strong>Display:</strong> <?php echo rwmb_meta( 'testing_data', '', 123 ) ?>
    </p>
    Thread Starter ace0930

    (@ace0930)

    @longnguyen89 But I wanna display it on a specific post type and not a specific post. If I pass the post ID to the third parameter, it won’t work on other posts even on the same post type? If I leave the third parameter empty, it then does not show on all the posts of the same post type.

    For example, if there are three posts (apple, orange, and watermelon) where they got the same post type ‘fruit’, if I specify the post ID (say like apple, assume the ID is 123) to the third parameter. It then only shows on apple? And if I leave the third parameter empty, then all of the post (apple, orange, and watermelon) won’t also show the field value even they’re on a same post type?

    Plugin Support Neo WhiteRabbit

    (@longnguyen89)

    Hi,

    Use the specific post ID just to check the helper function works correctly. You can change the fixed post ID by the WordPress function get_queried_object_id() to get the current post ID dynamically.

    <?php echo rwmb_meta( 'testing_data', '', get_queried_object_id() ) ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘rwmb_get_value() is not working’ is closed to new replies.