John Davidson

php - If custom field value is greater than x echo image?

0 comments
Message:


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.



My Answer:
>ID, 'custom_field_name', true ) ) {
echo 'Image';
}

To modify this code to only display the image if the custom field value is greater than a certain value (let's say x), you can use the following code:

php
$custom_field_value = get_post_meta( $post->ID, 'custom_field_name', true );

if ( $custom_field_value && $custom_field_value > x ) {
echo 'Image';
}


Replace 'custom_field_name' with the actual name of your custom field and x with the value you want to compare against. This code will only display the image if the custom field value is greater than x.

Rate this post

3 of 5 based on 8414 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us