Support Forum ยป User Profile

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in reply to: Shortcode to read out specific array elements #10675
    quint_rabbitquint_rabbit
    Participant

    Okay, I think I have done it!!
    Long trial and error.
    Please give me feedback on whether what I have done is a good idea!
    Suggestions for improvements welcome!

    I have created a new shortcode my_meta2 and I am calling it like this:
    [my_meta2 meta_key="key_topic_1" element="topic"]
    [my_meta2 meta_key="key_topic_1" element="obj1"]

    In functions.php I have added this code:

    add_action( 'init', function () {
      add_shortcode( 'my_meta2', function ( $atts ) {
        $atts   = shortcode_atts( [
          'meta_key' => '',
          'element' => '',
          'post_id'  => get_the_ID(),
        ], $atts );
        $value = rwmb_meta( $atts['meta_key'], array(), $atts['post_id'] );
    
    return $value[$atts['element']];
    } );
    } );
    in reply to: Outputing Field elements using Shortcode #9129
    quint_rabbitquint_rabbit
    Participant

    Hi,
    to which file in WordPress do I need to add this code?
    How can I ensure that it will not be overwritten by automatic WordPress updates?

Viewing 2 posts - 1 through 2 (of 2 total)