Inside the loop, you can check the custom field with get_post_meta. Like this.
If custom field randomname exists then it will show it’s value otherwise it will print <div class="name">content</div>
<?php
if ( get_post_meta( $post->ID, 'randomname', true ) ) {
echo get_post_meta( $post->ID, 'randomname', true );
} else {
echo '<div class="name">content</div>';
}
?>
OR you can use below which is shorter version of above using Ternary Operator
echo get_post_meta( $post->ID, 'randomname', true ) ? get_post_meta( $post->ID, 'randomname', true ) : '<div class="name">content</div>';
Related Posts:
- How to handle a custom form in wordpress to submit to another page?
- How to display multiple Post meta_key/meta_values by SQL query
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- How to make an meta_query optional?
- How to use multiple query with same meta key
- How can i create a function to get youtube video time
- How to loop over custom fields in a page template?
- How can update custom meta for all posts
- Unique key for each row in a repeater field
- Removing WordPress profile fields from non-admins
- Use ajax to update_post_meta
- If Meta Checkbox is checked, do something?
- Custom field value not saving when it contains a URL?
- tracking number field in Woocommerce order [closed]
- How can I create a list of page titles from custom meta values?
- Sort posts by custom fields value using dropdown menu
- WordPress – Display array data of a child
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Need Help Fixing My Iframes [closed]
- Adding number to date not working [closed]
- Saving and Restoring a Canvas on A Individual User Basis
- How to use thumbnail size of image if I’m only using src to get image
- 3 Slashes appear after Apostrophe in custom fields after updating product-site
- how to retrieve a value if a checkbox is checked
- Trouble checking if custom woocommerce checkout field is empty or not
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Add / Update Custom Fields After Select Pictures in Media Window
- Automatic Shortcode Creation with Custom Fields [closed]
- How would an if statement surrounding a custom field with two variables (holding values) look like?
- How to combine 2 php functions into one function with a custom field
- Advanced Custom Fields – display label and value only if value entered
- Saving zero in meta box
- How to check if a PHP string is different than meta field?
- Why does this update_post_meta function not delete the custom field itself?
- Only show image from custom field when present
- Hide Heading if ACF Field is empty
- Custom meta box values are not getting saved for my custom post type
- WP_Query: getting posts where custom field exists
- Creating an image from a custom field
- User Meta Value not echoing despite Var_Dump Showing correct string
- WordPress loop by meta key that is an array? and how loop multiple arrays
- WP All Import / Update stock quantity from multiple XML files
- Concatenate Custom Field Value & HTML Value
- `update_post_meta` not working anymore
- Unable to render custom field after attempt to generate a list of recent post in page template
- Define category ID using get_post_meta
- Hide a div when a custom field is empty
- Conditional On custom field plugin metabox
- Adding custom url to readmore link using get_permalink()
- Filter unique custom field value based on custom taxonomy category or other custom field
- Add “alt” Attribute to GD Star Rating Tags
- Display background color or image with custom meta box?
- custom header text
- Meta boxes only displayed when editing normal (default wp post_type) posts
- WordPress stripping out custom field tags
- Can ‘Custom Field’ data be inserted into this Short Code?
- Using an “IF” statement based on the existence of custom field
- Query pulling a single post per month
- Add custom fields from different posts
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- Adding a custom meta field with default NULL value which is not selectable
- How do you save the values from custom fields to a products data
- Order category posts by last word of custom field
- Products listing check if meta checkbox is checked
- Is it possible to update the dataset using update_post_meta
- How to update custom fields when post is published?
- Block error message in foreach loop when looping through ACF field
- Hide a div if the fiels is empty
- Inserting a class on before_widget if checkbox is checked
- What is the correct way to search 3 custom fields only in WordPress?
- wp_get_nav_menu_items() with ACF
- How do I get the value of a current user’s custom field?
- Get field in readable word
- How to display custom field from a gallery thumbnail?
- Get meta_query value by user meta array
- Getting a value from a custom field from a page that shares a parent with the current page
- Custom fields changes the formatting of metabox input
- Include a custom field in mysql query
- Display Content Based on Custom Field Value
- If custom field doesn’t exist, or exists and it’s true show title?
- How to link a word comprised of a custom field with another?
- Custom field in title
- How can I put a custom field as the link of a button shortcode?
- Outputting a custom field in PHP
- Custom fields randomly stop working
- Where can I find the code for the menu page meta boxes?
- I want Page titles and excerpts to show up on home.php in certain order
- Posts sortable column not sorting properly for custom field numbers
- ACF Date fileds to Age Convert [closed]
- Save custom field value to variable for conditional – why is this not working? [closed]
- Metadata on the WP_Post object
- Appending an ACF custom field to the page title
- Grabbing value of input field inside of array
- Convert custom field date format to “WordPress default”
- How can I change the location where the custom field is displayed in the Quick Edit tab in WordPress
- Shortcode Displays 2 times
- How to execute a shortcode within a custom field?
- How to create advanced custom fields for backend content
- Exclude function for custom pages, exclude custom ACF fields
- Allow HTML in custom taxonomy description, and show it on front end