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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.