• 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)
Viewing 1 replies (of 1 total)
  • The topic ‘Checking for custom field value inside function.php’ is closed to new replies.