0

How create corect function with this code?

<?php $price = get_post_meta($id, 'price_input', true);

    if ($price != ''){
        echo $price . " Euro";
    }
    else {
        echo "None";
    }
 ?>

I want to put this code in function.php or another place and use <?php myfunction(); ?>

Thx for answer!

1 Answer 1

1

That's pretty straight forward PHP:

#in functions.php
function display_price( $post_id ){
    $price = get_post_meta($post_id, 'price_input', true);

    if ($price != ''){
        echo $price . " Euro";
    }
    else {
        echo "None";
    }
}

in your template:

<?php display_price( $id ); ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.