Title: Checking for custom field value inside function.php
Last modified: August 19, 2016

---

# Checking for custom field value inside function.php

 *  [kab2512](https://wordpress.org/support/users/kab2512/)
 * (@kab2512)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/checking-for-custom-field-value-inside-functionphp/)
 *     ```
       function child_exclude_category($query) {
   
       global $post;
       $cat = get_post_meta($post->ID, 'artikel', true);
       if ($cat =='') { $cat = '-1,-3,-12'; }
       else { $cat = '-1,-3'; }
   
       	if ( $query->is_home ) {
       		$query->set('cat', $cat);
       		$query->set('orderby', 'date');
       		$query->set('order', 'desc');
       		$query->set('posts_per_page', '20');
       	}
       return $query;
       }
   
       add_filter('pre_get_posts', 'child_exclude_category');
       ```
   
 * I have a question regarding checking for a customfied inside function.php for
   the childtheme.
 * As you can see in the example above – i would like to check if a certain custom
   field value exists and if not a certain categori 12 should not be included in
   the query_post.
 * But i dosnt seem to work 🙁
    What am i doing wrong
 *     ```
       global $post;
       $cat = get_post_meta($post->ID, 'artikel', true);
       if ($cat =='') { $cat = '-1,-3,-12'; }
       else { $cat = '-1,-3'; }
       ```
   

Viewing 1 replies (of 1 total)

 *  [Alwyn Botha](https://wordpress.org/support/users/123milliseconds/)
 * (@123milliseconds)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/checking-for-custom-field-value-inside-functionphp/#post-1930974)
 * [http://codex.wordpress.org/Custom_Fields#Internal_Functions](http://codex.wordpress.org/Custom_Fields#Internal_Functions)
 * >  These functions are intended for use inside The Loop,

Viewing 1 replies (of 1 total)

The topic ‘Checking for custom field value inside function.php’ is closed to new
replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Alwyn Botha](https://wordpress.org/support/users/123milliseconds/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/checking-for-custom-field-value-inside-functionphp/#post-1930974)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
