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:
- Pass a PHP variable to another file
- How to store the_title() into a variable to reutrn the value, not just echo it
- Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
- The values of custom fields are not available functions.php
- Unique key for each row in a repeater field
- Can an array be used as a meta_query value?
- ACF check if variable has http, if else return string
- Looking for most performant way to execute several similar WP queries within shortcodes
- 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
- Trouble With Conditional Logic in PHP
- Using a variable in is_page(array())
- How to put a variable in a instance in the widget
- Using Advanced Custom Fields to create a per page slider
- get_term_link() returns correct – But illogical error-messages disturb
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Remove the first 5 characters of the_title and orderby that
- How to use thumbnail size of image if I’m only using src to get image
- How to modify a global variable in a function and use it on another function?
- Sort by page information by Ascending Numbers
- Advanced Custom Fields – display label and value only if value entered
- Download PDF after CF7 form submission
- WordPress function and string as variable?
- Create a WordPress shortcode using PHP [duplicate]
- Creating WordPress Shortcode with Variable
- How to put a form with php code into a variable or shortcode?
- Upload non-featured image to image field
- Get access to variable from previous pageview, excluding ajax-calls
- HTML Special Characters in URL string [closed]
- InnerBlocks with allowedBlocks not working with acf_register_block
- Pass Variables or Variable Place-Holder from Editor to PHP
- Accessing values from ACF sub field (flexible content area) in PHP
- Creating an image from a custom field
- ACF & Bootstrap Gallery Shows Blank Slides [closed]
- ACF Repeater Pagination stopped working since upgrade to php7.2
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- Refactoring long if/else php chains
- Getting taxonomy category Image from ACF [closed]
- Store and Change Session variable – PHP SESSION VARIABLE
- Overide Variable in Child Theme
- Show get_sub_field value if it exists [closed]
- Update post meta – Custom field does not match meta-key
- Dynamically adding filters
- PHP variables in a post?
- Display Post Title From Select Choice Loop in Advanced Custom Fields (ACF) – WordPress
- Add class to all img if they have a certain ACF field
- Delete images from media library when user deletes an image from ACF Gallery
- Display acf taxonomy attachment
- How to send a php var to jQuery Ajax call with two different file
- Nested Queries of decreasing specificity
- Unable to display multiple parameters from url by javascript through shortcodes
- How to check a variable Changes
- ACF: Display Google Map in frontend issues
- Bootstrap 4 Carosuel with ACF Repeater field
- global $product is empty string when passed into function
- How to display acf field values from home page on all pages?
- Set ACF on order during checkout
- Best way to use variables in multiple functions?
- Trying to add some custom text into WordPress Post title via function.php
- Reduce Stock Based on Custom Variation Field Rather than Attribute (Working Script)
- ACF relationship on user profile page used for allowed access
- Get field value and use as variable in php
- How to change the value of a variable using input field?
- get_template_part() not working with Advanced Custom Fields plugin
- List all ACF field values across every post on one page
- Javascript Tab Gallery with Advanced Custom Fields
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- How can I copy an ACF field to AIOSEO field? [closed]
- How to find php variable of wordpress theme settings
- Make sticky post with FacetWP
- Generate a radius search of custom post type locations
- Add class to all meta boxes for a custom post type
- WooCommerce Custom Tab with ACF Repeater Field
- PHP for loop not working as intended
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- Passing parameter from the current URL to redirect to another url
- Undefined variable & issue with smof_data
- Display a single row from nested array of custom field data
- Pulling a variable into the wp_nav_menu function
- Else if Statement for Advanced Custom Fields [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?
- get_category only returning details for ‘uncategorized’
- Custom field within shortcode
- Shortcode not passing variable to included file
- Can’t get options with $data[‘variable’]
- Advanced custom fields Repeater conditional statement not working [closed]
- PHP Use Declared array Variable inside already Declared Array
- Import and use a variable in additional settings of Contact Form 7 [closed]
- WP query with variables gives no result for specific user
- Show button in header when product custom field is not empty
- advanced custom fields: repeater field within conditional statement [closed]
- “acf/load_field” Critical error upon saving/updating WooCommerce products [closed]
- Cannot Access ACF Field Values via my Plugin
- Get check box values inside array for use in posting form data
- Add up all numbers from a WordPress query [closed]