Support

Account

Home Forums General Issues Image field on term returning ID instead of Array Reply To: Image field on term returning ID instead of Array

  • It’s extremely difficult to eliminate all the possibilities like in the original post.

    For example, adding additional post type to a site would mean having additional problems in the future. Or returning posts that you don’t want from a post type you don’t really want for search results.

    A better solution would be to make sure that you are currently querying a post type that can have ‘category’ as a term.

    
    function alter_category_query($query) {
    	if(is_category() && empty($query->query_vars['suppress_filters']) 
               && empty($query->query_vars['suppress_filters']) ||
               $query->query_vars['suppress_filters'] == 'post') {
    		$query->set('post_type', array('course'));
    		return $query;
    	}
    }
    add_filter('pre_get_posts', 'alter_category_query');
    

    The above will only make the change if you’re currently doing a query for posts and you won’t need to worry about future changes causing problems you’ll need to track down.