Title: Conditional Display logic for custom fields
Last modified: September 2, 2024

---

# Conditional Display logic for custom fields

 *  Resolved [pagecrawler](https://wordpress.org/support/users/pagecrawler/)
 * (@pagecrawler)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/conditional-display-logic-for-custom-fields/)
 * How do I display a widget on custom post pages where the value of a custom field
   dictates whether to display or not:
 * $customfield= get_post_meta( $post->ID, ‘_unavailable’, true );
 * if ($customfield === ‘yes’);
 * The above results in the widget not displaying at all.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Mej de Castro](https://wordpress.org/support/users/mej/)
 * (@mej)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/conditional-display-logic-for-custom-fields/#post-17994041)
 * Hi [@pagecrawler](https://wordpress.org/support/users/pagecrawler/),
 * Thanks for reaching out to our support threads. Could you please try using either
   of these codes?
 * get_post_meta( $post->ID, ‘_unavailable’, true ) === ‘yes’
 * get_post_meta( get_the_ID(), ‘_unavailable’, true ) === ‘yes’
 * Thanks and please let us know if this works for you.
 * Regards,
   Mej, from the Widget Options Team
 *  Thread Starter [pagecrawler](https://wordpress.org/support/users/pagecrawler/)
 * (@pagecrawler)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/conditional-display-logic-for-custom-fields/#post-17996766)
 * Thank you for your support.
 * Unfortunately the above code does not work. The widget does not appear on the
   front end when either of the codes are used, even when reversing the statement
   eg:
 * get_post_meta( $post->ID, ‘_unavailable’, true ) !=== ‘yes’
 *  Plugin Author [Mej de Castro](https://wordpress.org/support/users/mej/)
 * (@mej)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/conditional-display-logic-for-custom-fields/#post-18010175)
 * Hi [@pagecrawler](https://wordpress.org/support/users/pagecrawler/),
 * It is working on our end. But I understand we might have different set up. We
   will look further into this.
 * Kind Regards,
   Mej, from the Widget Options Team
 *  Plugin Author [Mej de Castro](https://wordpress.org/support/users/mej/)
 * (@mej)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/conditional-display-logic-for-custom-fields/#post-18062156)
 * Hello [@pagecrawler](https://wordpress.org/support/users/pagecrawler/) 
   I have
   reviewed the code snippet:
 * `get_post_meta( get_the_ID(), '_unavailable', true ) === 'yes'`
 * It is working correctly on my end.
 * Could you please confirm if the value saved in `get_post_meta( get_the_ID(), '
   _unavailable', true )` is actually `'yes'`? I ask because there is a possibility
   that the saved value might be the boolean `true` instead of the string `'yes'`.
   
   Thank you,Mej, from the Widget Options Team
 *  Plugin Author [Mej de Castro](https://wordpress.org/support/users/mej/)
 * (@mej)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/conditional-display-logic-for-custom-fields/#post-18122092)
 * Hi [@pagecrawler](https://wordpress.org/support/users/pagecrawler/),
 * I hope you are doing well. Have you managed to display a widget on your custom
   post pages using the cod snippet?
 * Thanks and we are waiting for your reponse.
 * Kind Regards,
   Mej, from the Widget Options Team

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Conditional Display logic for custom fields’ is closed to new replies.

 * ![](https://ps.w.org/widget-options/assets/icon-256x256.gif?rev=2513739)
 * [Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets](https://wordpress.org/plugins/widget-options/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/widget-options/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/widget-options/)
 * [Active Topics](https://wordpress.org/support/plugin/widget-options/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/widget-options/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/widget-options/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Mej de Castro](https://wordpress.org/support/users/mej/)
 * Last activity: [1 year, 7 months ago](https://wordpress.org/support/topic/conditional-display-logic-for-custom-fields/#post-18122092)
 * Status: resolved