Title: Adding Message Depending on Custom Field
Last modified: August 19, 2016

---

# Adding Message Depending on Custom Field

 *  Resolved [Tom Morton](https://wordpress.org/support/users/tm3909/)
 * (@tm3909)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/adding-message-depending-on-custom-field/)
 * So my homepage is a page within wordpress. It has a custom field that is defined
   by custom meta boxes. Essentially, at all times the custom field of the homepage
   will be either LIVE or STANDARD.
 * I want to write a function in my functions.php file that will allow me to show
   an “error” or “message” box (Ala All In One SEO, or when you save a post) that
   will notify anyone logged in that the custom meta is X.
 * So if the specific page (id=476) has a custom field “broadcast” that has the 
   variable “live”, it shows an error or message box across the admin.
 * ::EDIT:: So I forgot to mention that I’m trying to get this message to appear
   in the WP-admin not the normal site ::/EDIT::

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

 *  [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/adding-message-depending-on-custom-field/#post-1715357)
 * I’m curious as to what your desired result is?
 *  Thread Starter [Tom Morton](https://wordpress.org/support/users/tm3909/)
 * (@tm3909)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/adding-message-depending-on-custom-field/#post-1715358)
 * Thanks for the reply. Here’s whats going on. I’m live streaming a show, but we
   don’t live stream all the time. When we are live streaming, I have a custom template
   that loads. I enable this using a custom field set on my “homepage” page.
 * I want to check IF the custom field =’s “live”, then execute the admin_notice
   that I have written. If it does not = live, then do nothing.
 * This gives a message to anyone logged into the admin panel that live streaming
   is enabled.
 *  Thread Starter [Tom Morton](https://wordpress.org/support/users/tm3909/)
 * (@tm3909)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/adding-message-depending-on-custom-field/#post-1715364)
 * Just to give a little more detail, I’ve got this going in my functions.php so
   far. Everything works except for checking what the custom field is. Right now,
   it doesn’t matter if the custom field = live or standard, it shows the error 
   alert regardless.
 *     ```
       global $wp_query;
       $postid = '476';
       $customField = get_post_meta($postid, 'broadcast', true);
   
       if(isset($customField['live'])){
   
       function live_message(){
       echo '<div class="error fade" style="background-color:#FFEBE8;">
           <p style="font-size:13px;"><strong>You are Broadcasting Live!</strong></p>
           <p><a href="' . admin_url( '/post.php?post=476&action=edit' ) . '">Click here</a> to edit the homepage and turn live streaming mode off. If you want to continue to live stream, ignore this message!</p>
   
           </div>';
   
       }    add_action( 'admin_notices', 'live_message');
   
       } else {}
       ```
   
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/adding-message-depending-on-custom-field/#post-1715368)
 * Didn’t test this but:
 *     ```
       function my_admin_notice() {
       $pageid = 476 ;
       $broadcast = get_post_meta($pageid, 'broadcast', true);
       if ($broadcast == 'live') {
           echo "
           <div id='my_admin_notice' class='updated fade'><p><strong>".__('This is my message.')."</strong> ".sprintf(__('Hello there.'))."</p></div>
              ";
         }
       }
       add_action('admin_notices', 'my_admin_notice');
       return;
       ```
   
 *  Thread Starter [Tom Morton](https://wordpress.org/support/users/tm3909/)
 * (@tm3909)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/adding-message-depending-on-custom-field/#post-1715370)
 * [@michaelh](https://wordpress.org/support/users/michaelh/) I honestly don’t know
   how you got so good at WordPress, but it seems like you always come through. 
   I really appreciate it man, thanks so much!
 * Its guys like you who motivate me to get in the forms and help out, even if I’m
   not exactly at “guru” status just yet.
 * Thanks again!
 *  [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/adding-message-depending-on-custom-field/#post-1715373)
 * Before I post a solution – do you want a message to show that says ‘You’re off
   air’ or something like that? Or nothing to show at all when the box is empty?
 *  [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/adding-message-depending-on-custom-field/#post-1715374)
 * Yeah that’s pretty much what I would’ve done (almost)
 *  Thread Starter [Tom Morton](https://wordpress.org/support/users/tm3909/)
 * (@tm3909)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/adding-message-depending-on-custom-field/#post-1715377)
 * Two questions for you guys. One, the ‘return;’ line breaks my sidebar, basically
   gives me an error saying “your theme does not support sidebar widgets”. I deleted
   it, and everything still works. Is that cool or dangerous?
 * Two, I would assume the same technique could be used for the front end as well.
   Example, check if the custom field =’s live, and if so display the live embed
   stream?
 * Thanks!

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

The topic ‘Adding Message Depending on Custom Field’ is closed to new replies.

## Tags

 * [custom message](https://wordpress.org/support/topic-tag/custom-message/)
 * [error message](https://wordpress.org/support/topic-tag/error-message/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [Tom Morton](https://wordpress.org/support/users/tm3909/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/adding-message-depending-on-custom-field/#post-1715377)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
