Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to show custom field on specific custom post type posts only when filled

Take a look at the WP’s template hierarchy. When a page is requested WordPress searches for the file to load in a specific order. You can create a template specific to your custom post type. You would copy the file called single.php and name the copy single-{post_type}.php where “post_type” is the name of your CPT. This file would then load instead of single.php every time a single custom post type page was requested.

As for only displaying the field, you could check if it has a value in an if() statement. When you validate the feild’s value when the post is saved you can check if the user set anything, if they did not then you should set it to something falsy like an empty string.

Then the check in the template file would look something like this:

<?php
    $meta_author = get_post_meta( $post->ID, 'dublin_core_author', true);
    $meta_contributor = get_post_meta( $post->ID, 'dublin_core_contributor', true);
    if ($meta_author != '' && $meta_contributor != '') :
        echo '<p>
              Auteur: ' . $meta_author . '<br>
              Contributor: ' . $meta_contributor . '<br>
              </p>';
    endif;
    ?>

<!--Other template html-->

Related Posts:

  1. Displaying Meta Box Image
  2. what is the correct way to compare dates in a WP query_posts meta_query
  3. Advanced search form with filters for custom taxonomies and custom fields
  4. Custom field values deleted when trashing custom post type
  5. How to get all custom fields of any post type
  6. Admin Area Custom Type Search By Meta Fields Without Title & Content
  7. How do I Paginate Search Results for Custom Post Types?
  8. How Can I save multiple records in same meta key?
  9. Detect meta value changes when post is updated (post_updated)
  10. Search everything (posts, pages, tags, cpt, meta)
  11. How to get source of custom meta image?
  12. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  13. Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
  14. Create a random unique 6 digit number as custom field for custom post type
  15. how to interconnect custom post types?
  16. List all images from a single post meta value
  17. Populate Custom Fields in a Custom Post Type?
  18. Meta Key Value in current-user-only loop
  19. How to check if user meta field is empty in conditional else statement
  20. How to implement a Google map store locator
  21. Posting to a Custom Post Type from front end – user generated content
  22. Update Post Meta for a logged in user
  23. A better way to add a meta box to custom post types
  24. Two Custom Post Types Many to Many Relationship
  25. get_post_meta not working on publishing
  26. How do I set all of a particular post meta to a value within the custom post type I’m in?
  27. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  28. Importing Data from a Non-WordPress database, into WP
  29. Custom fields for custom post type
  30. Check if post with same meta value exists
  31. Submitting Custom Post Types with custom fields from Front-end form
  32. create custom meta box with default value
  33. List of users that clicked a ‘Join’ button at single post
  34. delete_post_meta() for whole CPT / multiple posts?
  35. How to get specific post meta by title or id
  36. Inserting custom fields into single.php
  37. hide specific div on single.php [closed]
  38. copy images from custom field to another custom field
  39. Cannot obtain custom meta information
  40. How can I output WPAlchemy repeating fields meta values in my page template?
  41. How to call a post’s metadata in shortcode.php?
  42. delete duplicate meta_value with same post_id
  43. Search CPT Title AND Meta
  44. updating one custom meta field only
  45. Add a class to post_class if more than one post shares same meta_value_num
  46. Add a meta field to the list of results for a custom post type
  47. Empty meta-box returns publishdate if no value is set?
  48. Filter search posts by post meta?
  49. Custom fields for post or terms which don’t update on post update
  50. Custom Post Type meta data getting deleted on bulk editing taxonomies
  51. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  52. How to keep custom post type related information
  53. How can I add a meta[] to my custom post type and search by term with the Rest API?
  54. Show posts from WP Custom Post Type selected from a field in a metabox
  55. Creating an archive page or simple template to list all values of a custom field of specific post type listing
  56. Where is get_post_meta value located?
  57. Custom meta fields not showing up in WP_Response Object via custom endpoint
  58. How to Disable option of meta field if that option is selected for any other post in custom post type?
  59. Add more custom fields when creating a new custom post type
  60. How do I extract the contents of a CPT’s custom field for all posts?
  61. Delete custom post type metadata without deleting the post in admin area
  62. How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
  63. How to add post reference field to a plugin?
  64. Advanced search form with filters for custom taxonomies and custom fields
  65. Querying meta values within an array
  66. Display a list of posts whose meta field values are equal to the ID of the post being viewed?
  67. Check for custom field value in different post type than current one and do something
  68. meta query multiple values for the same key
  69. Problem with multi checkboxes value in metabox?
  70. How can I register multiple custom post fields to json?
  71. How to get post by meta value
  72. Sort custom post archives by a meta value from a different custom post type?
  73. filter using custom fields
  74. Show Post columns to specific users on condition
  75. Displaying Custom Fields from Custom Post Types [closed]
  76. Change picture attachment meta of all occurrences of a picture
  77. Unknown Post Meta Records
  78. Displaying posts inside table having issues
  79. Get Previous Post based on Custom Field Name, for Custom Post Type
  80. Get meta values from parent post and save in child post
  81. Custom post types – meta_query: search lesson which starts sooner
  82. Saving custom post types post_meta over REST-API fails
  83. Sql Update CPT from publish to draft and particular custom field
  84. How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
  85. Custom post types & Pages hierarchy – Error 404
  86. Ordering Post by Meta Key (Not Working)
  87. Post Filtered by Custom Field Value
  88. How do I get all authors posts of a custom post type outside loop
  89. Adding a Section for Visitors
  90. Error when moving custom post type to bin
  91. add action save post type and update post meta woocommerce
  92. Automatic Set Category For A Custom Post Type
  93. How to link custom field of two custom post types?
  94. get_post_meta not working with variable as a post_id for dynamically get the postid
  95. Why custom post redirecting to index page?
  96. How to make “single post” permalink maintain it’s sub-page structure
  97. Custom Function to redirect singular post if specific meta field is empty
  98. How to replicate data storage and querying using WordPress. Custom posts/fields or Custom db tables?
  99. Filter custom WP_Query by first letter of a custom field – hopefully using Search and Filter Pro?
  100. CPT – Custom Text fields point to new url permalinks
Categories custom-post-types Tags custom-field, custom-post-types, post-meta, single
Custom template for all woo commerce categories
How to handle this specific case of custom post type?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress