php - If custom field value is greater than x echo image?
Get the solution ↓↓↓Right now I have a code to display an image if the custom field value is available:
if ( get_post_meta( $post->ID, 'usp-custom-stockup', true ) ) {
echo '<img src="http://www.website.com/images/rocket_ico.png" align="left">';
} else {
echo "";
}
But I want to display the image if the value is equal or greater than 50. I have this code so far. I guess I need to mix the above code into this one:
if($usp-custom-stockup > 50)
{
echo '<img src="http://www.website.com/images/rocket_ico.png" align="left">';
}
But have no idea how.
Answer
Solution:
I'm not sure if this helps (because this is untested code), but is it possible to use something like this:
// ref: based on your code
// ref: https://developer.wordpress.org/reference/functions/get_post_meta/#comment-316
$usp_custom_stockup = get_post_meta( $post->ID, 'usp-custom-stockup', true );
if ( ! empty($usp_custom_stockup) ) {
if ( $usp_custom_stockup > 50 ) {
echo '<img src="http://www.website.com/images/rocket_ico.png" align="left">';
} else {
echo '';
}
}
// You can potentially deal with another else situation here if need be ...
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: can't write image data to path
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.