Create Function – Multiple IFs return custom fields
-
Hi,
I’m trying to create a function to query 6 custom fields (3 pairs) I have to determine if they have data. If they do, then I’d like to return that data (price and link) and output it onto the page. The final bit would be putting this function into a shortcode I can then use across the theme.
The customs fields are: go_price, go_link, bk_price, bk_link, ml_price, ml_link
My current function is:
function displayprice() { $return = ''; $go_price = get_field( 'go_price' ); $go_link = get_field( 'go_link' ); $bk_price = get_field( 'bk_price' ); $bk_link = get_field( 'bk_link' ); $ml_price = get_field( 'ml_price' ); $ml_link = get_field( 'ml_link' ); if( $go_price && $go_link ) { $return = '<a href="' . esc_url( $go_link ) . '">' . $go_price . '</a>'; } if( $bk_price && $bk_link ) { $return = '<a href="' . esc_url( $bk_link ) . '">' . $bk_price . '</a>'; } if( $ml_price && $ml_link ) { $return = '<a href="' . esc_url( $ml_link ) . '">' . $ml_price . '</a>'; } return $return; } add_shortcode( 'showprices', 'displayprice' );I’ve obviously got something wrong somewhere. It’s returning the first value but doesn’t return the rest. Could someone point me in the right direction?
Many thanks
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
The topic ‘Create Function – Multiple IFs return custom fields’ is closed to new replies.