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
- Pass a PHP variable to another file
- How to store the_title() into a variable to reutrn the value, not just echo it
- How do I make my function add variables/values to the $post object?
- Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
- If Custom Field is empty don’t display div
- The values of custom fields are not available functions.php
- Unique key for each row in a repeater field
- How do I know what variables are passed in a filter/action and what their meaning is?
- 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
- Trouble With Conditional Logic in PHP
- Using a variable in is_page(array())
- 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
- Get value from shortcode to do something
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Unable to write multiple values back to ACF user field – PHP
- Update grandchild repeater field with value per row
- 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]
- 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]
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- what is the method to echo class attribute inside the i tag? [closed]
- javascript variable to wordpress php variable
- 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
- Remove Post if Advanced Custom Field is checked to fix paging
- 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
- Display acf taxonomy attachment
- 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
- 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
- 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
- Custom WordPress Function – Adding items from Foreach Loop into an array and Updating Field based on array of IDs (ACF + WooCommerce)
- 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
- ACF number less than comparison not working