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

Display post meta conditionally based on it’s value

If it’s created with ACF, then the way to call the field is like this:

$can_download = get_field('enable_downloads',$postid);

so your code should look like:

<?php 
        global $wp_query;
        $postid = $wp_query->post->ID;                  
        $can_download = get_field('enable_downloads',$postid);
        if ($can_download == 'yes') { ?>

    <?php } elseif ($can_download == 'no') { ?>

    <?php } elseif ($can_download == 'other') { ?>

    <?php } else { ?>

    <?php } ?>

Related Posts:

  1. Can wp_query return posts meta in a single request?
  2. Getting attachments by meta value
  3. meta_query where value is equal to given value
  4. WordPress altering my custom query, How to fix it?
  5. Group WP_Query by meta_key date
  6. exclude posts with a specific custom field and value
  7. How to make Meta Query case sensitive?
  8. Display custom field meta outside loop, site wide
  9. Fetch Record based on meta key dates
  10. how to make members list directory through wordpress post custom meta key.
  11. Large AND OR query timing out
  12. Order WP_Query results by meta key value in custom query
  13. How do i create a custom post query when the meta value is an array?
  14. Trouble with serialized metadata
  15. Query against multiple locations within single custom post type post
  16. Meta key in wp_query bug?
  17. Sorting Posts with meta value not working
  18. Custom Search Query – include only custom fields and title
  19. Extend search query to search meta keys values based on search string
  20. How to only display posts whose meta_value field is not empty?
  21. order by numeric value for meta value
  22. How do I query for posts by partial meta key?
  23. Use REGEXP in WP_Query meta_query key
  24. Meta query with string starting like pattern
  25. compare meta_query in get_posts arguments
  26. WordPress retrieving meta data for all custom post types in list view
  27. Order by optional meta key?
  28. How can I use order_by to order by two meta_keys without excluding posts that don’t have those keys initialized?
  29. meta_query: using BETWEEN with floats and/or casting to DECIMAL
  30. Reduce or prevent calling of update_meta_cache
  31. Function in array as arguments for WP_Query
  32. Is there a way to extend WP_query so Custom Post Types can have properties?
  33. WP_Query to show post from a category OR custom field
  34. What is the most efficient way of querying posts based on visits and date for current day?
  35. Sorting posts by custom date fields (non standard date format)
  36. WP_Query displaying ALL posts
  37. Query Custom Meta Value with Increment
  38. WP-CLI How to generate a list of posts with corresponding meta values
  39. Get_post() with meta_key when compare is a date
  40. querying with custom meta field with meta_query
  41. Group posts by custom field
  42. Order by meta_value_num DESC and meta_value ASC on WP 4.0
  43. What is an efficient way to query based on post_meta?
  44. Custom query with category exclusion and post-meta “whitelist”
  45. WP_Query not working as expected for attachments and custom meta_query
  46. getting posts and number by specific meta value in multiple meta
  47. How to count post meta key values for all posts in database
  48. How to query using a combination of custom_field values?
  49. Sorting Posts by custom field
  50. Order posts by date and then by custom field
  51. Group posts by meta_key
  52. How should I use posts_where to change meta_value from a string to integer?
  53. Revolution Slider Orderby Two Custom Fields
  54. Query two post types and order by two different date fields
  55. How can I create a WP_Query that returns posts where one meta_value
  56. WP Meta Query for some meta (array) values
  57. Querying by taxonomy vs Querying by Custom fields Speed Comparison
  58. WP Query post meta value
  59. Would this post meta be better added to the post table rather than post_meta table
  60. Custom URl parameter
  61. query posts in functions.php and update a field
  62. Compile meta values from custom loop into array and then calculate sum total
  63. How to get sum of meta_values of a meta_key in wp_query according to conditions
  64. how to fire join query with post_meta
  65. Order by meta_key in custom post type doesn’t affect the query
  66. Best approach to create Hot and Trending sections
  67. WP_Query, custom sort and custom filter
  68. How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
  69. meta_key and meta_value not working together
  70. How can i make WP_Query return post image and categories?
  71. Custom Field sort not working (WP 3.8.1)
  72. Order posts by meta value and Date
  73. wp_query with multiple custom fields
  74. Efficient way to update multiple post meta
  75. How add a custom posttype name using ACF field to a query post array
  76. Filtering posts by custom field value not working
  77. How to make orderby ‘meta_value_num’ OPTIONAL?
  78. Display link to taxonomy archive only if it has posts with certain custom field values
  79. getting posts and number by specific meta value in multiple meta
  80. Ordering Posts Type A by Custom Fields of related Post Type B
  81. Query Posts depends on custom field inside repeater field using acf
  82. Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
  83. Order Posts by meta value AND published date
  84. Query post with meta_query where date is not in future
  85. Minimising Database Queries when using Advanced Custom Fields
  86. Get meta info related to current post
  87. Select from wp_post and multiple meta_value from wp_postmeta
  88. Pull post meta with post_query?
  89. Search Posts with Custom Fields as query
  90. wp_query add arguments using array_push if variable met
  91. WP_query posts closest to todays date
  92. How do I use wp_query for WordPress search?
  93. How To Fix WP Query Returns Results But Shouldn’t?
  94. Get posts for which a custom field is not present, with get_posts
  95. Output an array of terms for a ‘tax_query’ => array()
  96. Inserting serialized value into wp_postmeta using update_post_meta
  97. Add quicklink to in the Admin posts page where I can query by a meta_key
  98. Performance when getting post meta for post retrieved by meta value
  99. How to Filter Posts by Custom Fields?
  100. Get attachment by meta_key value
Categories wp-query Tags custom-field, post-meta, wp-query
SEO Title Tag and Meta Description for custom taxonomy
Force WordPress to be more random

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