In PHP, 0 == false == [] == '' == null
. A simple check to check if a variable or condition has a value will return false
if the value is equal to 0.
For 0
to return true as a valid value, you would need to make use of strict comparison by using the identical (===
) operator. Just remember, if you use ===
, not only the value must match, but the type as well, otherwise the condition will return false. If your values are a string, you should use '0'
, if they are integer values (which I doubt as custom field values are strings as single values), you should use 0
.
You can do the following check
$difficulty = get_field( 'difficulty' );
if ( $difficulty // Check if we have a valid value
|| '0' === $difficulty // This assumes '0' to be string, if integer, change to 0
) {
$value = $difficulty;
} else {
$value="n/a";
}
echo 'Difficulty: ' . $value;
Related Posts:
- How to add elements to an empty array in PHP?
- Display all values of custom a field created with ACF on a page
- Where to get information about array fields in $_REQUEST?
- Pass a PHP variable to another file
- How to store the_title() into a variable to reutrn the value, not just echo it
- Variables declared in header not available in other includes
- How do I make my function add variables/values to the $post object?
- Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
- Conditionally loading JavaScript based on the Advanced Custom Fields in the post
- If Custom Field is empty don’t display div
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- Conditional statement for parent, child and grandchild pages
- The values of custom fields are not available functions.php
- Problem with ACF shortcode with Repeater Field in WordPress? [closed]
- Unique key for each row in a repeater field
- where to include a php file
- How do I know what variables are passed in a filter/action and what their meaning is?
- How to Explode a Textarea Field and Echo each line separately, wrapped with HTML
- Advanced Custom Fields Image Field returning ID instead of URL [closed]
- Can an array be used as a meta_query value?
- When would you use $_post instead of $post?
- ACF check if variable has http, if else return string
- Advanced Custom Fields: Post Object – Not returning data [closed]
- Looking for most performant way to execute several similar WP queries within shortcodes
- ACF: Only get first row of a Repeater Field
- Locating Global Variables
- Pass PHP variable to JavaScript without inline JS
- Count the number of times the search form template gets included on a page
- Putting PHP variables into javascript [duplicate]
- Variable global scope [closed]
- Trouble With Conditional Logic in PHP
- How to rewrite URL with PHP variables with htaccess to a normal looking URL?
- Importing hard coded custom field into acf field
- Using a variable in is_page(array())
- Strip characters, Including spaces, for tel: link
- How can I add multiple ‘tax_query’ arrays via a loop?
- ACF page while loop breaks footer while loop
- Change output based on text field value
- Static variable and add_rewrite_rule?
- How to put a variable in a instance in the widget
- Using Advanced Custom Fields to create a per page slider
- Call global variable array() in woocommerce child/template
- get_term_link() returns correct – But illogical error-messages disturb
- Display PHP within HTML values
- Custom Taxonomy Link Text Echo Name Not Slug
- Page returning ID from array, how to return the correct values for post in acf wordpress
- how to add number value in front for variable [closed]
- Sort by multiple options in custom field
- If or/and statement advanced custom fields [closed]
- Top menu disapears in Category Pages when filtering using ACF
- ACF loop and php formatting
- Create and update Custom Cookie based on multiple GET and POST Values for first time visitors?
- the_post_thumbnail unless video id is added
- get_category only returning details for ‘uncategorized’
- Custom field within shortcode
- Difference in Get Variable Location
- If I define a variable in header.php, how do I make it available to templates?
- Shortcode not passing variable to included file
- Can’t get options with $data[‘variable’]
- Add comma between variables [closed]
- ACF Date fileds to Age Convert [closed]
- Advanced custom fields Repeater conditional statement not working [closed]
- Order woo products, but first products must be with acf fields
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- PHP Use Declared array Variable inside already Declared Array
- Import and use a variable in additional settings of Contact Form 7 [closed]
- Use ajax response in PHP function
- WP query with variables gives no result for specific user
- Custom WordPress Function – Adding items from Foreach Loop into an array and Updating Field based on array of IDs (ACF + WooCommerce)
- Show button in header when product custom field is not empty
- advanced custom fields: repeater field within conditional statement [closed]
- How can I get values from a custom post type depending on where I click on my SVG map?
- Creating posts with php-script + csv
- How can one use variables in a template or template part without polluting the global scope?
- ACF number less than comparison not working
- How to make my scroll bar show under condition
- PHP Warning: Attempt to read property “id” on null
- Advanced Custom Fields – How do I get field values of a group within a group field type
- “acf/load_field” Critical error upon saving/updating WooCommerce products [closed]
- How to get ACF field to show up on all posts on front end?
- Put ACF function output code the_terms
- Cannot Access ACF Field Values via my Plugin
- Advanced Custom Fields Auto Populating Field Values For Nested Repeater FIelds
- How to access admin menu labels and links on front-end?
- How to create advanced custom fields for backend content
- Phone number custom field and woocommerce updating issue noticed
- How to capture number input from wordpress form into acf field in woocommerce
- add class to woocommerce single product template gallery thumbnails if media attachment ACF field toggled (true/false)
- Alter main query to always list posts according to ACF number field
- Add css class ID to largest and smallest number a custom field in wp_query
- How to get default variation ID (woocommerce)
- create custom post type and populate custom fields using php
- Date not working correctly
- Get check box values inside array for use in posting form data
- Add up all numbers from a WordPress query [closed]
- WordPress per ACF – permalink is not working
- Why does my custom slug only show in Gutenberg editor after page refresh?
- Display posts in correct month order using single date custom field
- How can I save the HTML output of a WP_Query function as a variable?