WordPress.org

Ready to get started?Download WordPress

Forums

Checking for custom field value inside function.php (2 posts)

  1. kab2512
    Member
    Posted 3 years ago #

    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'; }
  2. 123milliseconds
    Member
    Posted 3 years ago #

    http://codex.wordpress.org/Custom_Fields#Internal_Functions

    These functions are intended for use inside The Loop,

Topic Closed

This topic has been closed to new replies.

About this Topic