Support

Account

Home Forums General Issues Bring value from ACF into WP Function Reply To: Bring value from ACF into WP Function

  • Yes, you need the post ID so you could add a global $post to reference the post object so something like:

    function buy_card_shortcode() {
        global $post;
        $card_details = get_field('card_id');
    
        $output = '<a class="buy-card-class" href="https://www.ebay.com/sch/i.html?_nkw='. $card_details .'">eBay</a>';
        return $output;
    }
    add_shortcode( 'buy_card', 'buy_card_shortcode' );

    I did adjust your output as I think there was an error there around where the variable was referenced, as well.