I would write a function to handle the monotony of this task.
function my_print_meta($id, $key, $alternate="")
{
if($value = get_post_meta($id, $key, true))
echo $value;
else
echo $alternate;
}
Notice in the function that I only call get_post_meta
once and store the value in a variable so that two separate database queries don’t need to be made. With this function set, I would then call it in a template file using:
my_print_meta(get_the_ID(), 'survey_home_type', 'No Home Type');
Now, realize that this function, with the way that it manages the “alternate” text might not work for your template, but this is just an idea to get you going
Related Posts:
- How to add a data attribute to a WordPress menu item
- Order posts (across the whole site) by metadata date
- Functions.php code that only runs on localhost?
- hook a functions to change wp-config from functions.php
- Relative URLs and hide /wp-content/themes/
- Disable visual editor on one specific page
- How to display random users with avatars
- Can the wp-plugins (Must Use Plugins) URL be targeted for use in functions.php?
- In a WordPress plugin, how do you output HTML code inside the DOM header? [closed]
- Slugs as breadcrumbs for Pages
- Different ‘WP_CONTENT_URL’ for different subsites in Multisite setup?
- Removing Unnecessary Text from Admin Menu without CSS
- Display WordPress Search
- Remove_filter (‘the_content’, ‘wpautop’) is not working
- Preferred Use of home_url()?
- Pages should have priority when using add_rewrite_rule
- Setting cookies in WordPress
- How to add iOS & fav icons to the theme?
- Defer all js except certain ones in functions.php file
- Getting RID of thickbox!
- Customize “the_posts_pagination” and put list instead div
- Automatically insert php function into post $the_content
- Multisite, either change the name of sample-page or create new page
- What is the “icon” parameter in wp_get_attachment_image_src used for?
- How to use thumbnails in gallery?
- Hide Author.php template from specific user role
- Customizer field value into functions.php variable
- wp_insert_posts keeps adding multiple pages
- How to display a default image for post thumbnail using functions.php?
- How can I load a javascript file that is type=”module” the WordPress way?
- How to manage arrays from custom functions stored in functions.php?
- Best practice when altering a parent theme function inside a child theme?
- list tags with count in author profile page
- Product Tags in Add New product as checkbox list [closed]
- Running a script before absolutely everything
- Auto delete post if certain custom field data is empty
- using `require` in my functions.php breaks the site
- Is it OK to include files using ABSPATH?
- Frontend tag edit/submit form
- How to fetch the name of the active menu?
- Limit length of first excerpt in the loop
- Custom function causes a 503 error after a couple of hours
- How can I show my latest tweet in my wordpress blog?
- check if the user is owner of current page
- How to set the default avatar of buddypress avatar [closed]
- How to retrieve the current post’s generated featured image size?
- Why There Is No “get content by ID” Function
- Function shortcode – Set Parameter
- Is there a way to prevent a function/method from being called outside a specific hook?
- attachment page template? only show attachments for current post?
- Conditional statement not working in function
- get_next_posts_link() returns no result despite available posts
- Randomizing wp_tag_cloud() in child theme
- Nav menus all outputting the same links
- Secondary Menu and Logged In Users
- Modify gform_other_choice_value for specific form and specific field in Gravity Forms
- Adding code before post title with the_title produces weird results
- Remove the month and year from a WordPress Date?
- How to insert class in each list of categories?
- Add Link to Users List (Backend) to open each users front-end profile
- Editing the formatting.php file vs functions.php file?
- How to make a new function that includes a template
- wp_usermeta – Read from database, but save function broken
- remove/hide wp-editor
- Function not saving unchecked checkbox
- Removing parent theme CSS without editing parent theme
- Entirely Different Functions.php per Page?
- Why is this function crashing my wordpress installation? [closed]
- Problem with shortcode inside a shortcode
- Hide Author By-Line if After Certain Date
- Can I use ‘Featured Image’ as a hero image and a thumbnail?
- wp_title() return random number
- Woocommerce Display Discount On cart
- How to offset main query without affecting other queries and backend
- ACF Date Form in Custom Admin Field
- How to add link rel tags on paginated posts?
- How to pass data from a plugin to functions.php
- Function to disable “href” anchor tags that contain “a data-name” on mobile only
- Execute jQuery with custom event listener after successfully add an item to the cart
- WordPress hooks to call a function inside a construct
- WordPress undefined function error on using add_action() in functions.php
- How to create admin ajax function for my contact form
- Translation Function missing text-domain [closed]
- how to display featured image for single post for a specific category
- Load a Child Theme’s style.css just before the closing tag
- Can’t wrap my head around this function – any help would be appreciated
- Figure inlined width trigger distorted layout
- save_post hook – headers already sent?
- Exclude javascript in certain page url and all following url’s after forward slash
- How to use WP_rewrite?
- Shortcode Variations?
- How to test for a class (from a plugin) in functions.php
- Child Theme not working – CSS gone
- Custom shortcode not being included in content paragraph [duplicate]
- Display post_meta-by_key on product catalogue
- What are the parameters are used in add_action and filters?
- Which template file to edit to edit homepage in Mystile [closed]
- Does functions.php apply to every page?
- Comment turned Invisible
- How to add more than one menu for logged in members?