Skip to main content
added 1067 characters in body
Source Link

I'm not sure I got it right but the following snippet should excludeReplace all the featured category from displaying from most ofcall to in_category('featured') with the front-endcustom function inCategory('featured'), declare it on your functions.php:

add_filter/**
 * @param string $category
 *
 * @return bool
 */
function inCategory('get_object_terms'$category)
{
    global $wpdb, $post;

    if ( ! $post) {
        return false;
    }

    $query = $wpdb->prepare("SELECT COUNT(t.term_id)
    FROM $wpdb->terms AS t
    INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id
    INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
    WHERE tr.object_id = %d
    AND tt.taxonomy = '%s'
    AND t.slug = '%s'
    ", $post->ID, 'category', $category);

    return (bool) $wpdb->get_var($query);
}

The add the following filters:

/**
 * @param array $terms
 *
 * @return array
 */
function remove_featured_category_from_frontend(array $terms)  
{
    if ( ! is_admin()) {
        $terms = array_filter($terms, function ($term) {
            if ($term->taxonomy === 'category') {
                return $term->slug !== 'featured';
            } 

            return true;
        });
    } 

    return $terms;
}

add_filter('get_terms', 'remove_featured_category_from_frontend');
add_filter('get_object_terms', 'remove_featured_category_from_frontend');

Give it a try and let me know.

I'm not sure I got it right but the following snippet should exclude the featured category from displaying from most of the front-end.

add_filter('get_object_terms', function (array $terms) {
    if (!is_admin()){
        $terms = array_filter($terms, function ($term) {
            if ($term->taxonomy === 'category'){
                return $term->slug !== 'featured';
            }
            return true;
        });
    }
    return $terms;
});

Give it a try and let me know.

Replace all the call to in_category('featured') with the custom function inCategory('featured'), declare it on your functions.php:

/**
 * @param string $category
 *
 * @return bool
 */
function inCategory($category)
{
    global $wpdb, $post;

    if ( ! $post) {
        return false;
    }

    $query = $wpdb->prepare("SELECT COUNT(t.term_id)
    FROM $wpdb->terms AS t
    INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id
    INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
    WHERE tr.object_id = %d
    AND tt.taxonomy = '%s'
    AND t.slug = '%s'
    ", $post->ID, 'category', $category);

    return (bool) $wpdb->get_var($query);
}

The add the following filters:

/**
 * @param array $terms
 *
 * @return array
 */
function remove_featured_category_from_frontend(array $terms) 
{
    if ( ! is_admin()) {
        $terms = array_filter($terms, function ($term) {
            if ($term->taxonomy === 'category') {
                return $term->slug !== 'featured';
            } 

            return true;
        });
    } 

    return $terms;
}

add_filter('get_terms', 'remove_featured_category_from_frontend');
add_filter('get_object_terms', 'remove_featured_category_from_frontend');

Give it a try and let me know.

added 13 characters in body
Source Link

I'm not sure I got it right but the following snippet should exclude the featured category from displaying from most of the front-end.

add_filter('get_object_terms', function (array $terms) {
    if (!is_admin()){
        $terms = array_filter($terms, function ($term) {
            returnif ($term->taxonomy === 'category'){
 &&               return $term->slug !== 'featured';
            }
            return true;
        });
    }
    return $terms;
});

Give it a try and let me know.

I'm not sure I got it right but the following snippet should exclude the featured category from displaying from most of the front-end.

add_filter('get_object_terms', function (array $terms) {
    if (!is_admin()){
        $terms = array_filter($terms, function ($term) {
            return $term->taxonomy === 'category' && $term->slug !== 'featured';
        });
    }
    return $terms;
});

Give it a try and let me know.

I'm not sure I got it right but the following snippet should exclude the featured category from displaying from most of the front-end.

add_filter('get_object_terms', function (array $terms) {
    if (!is_admin()){
        $terms = array_filter($terms, function ($term) {
            if ($term->taxonomy === 'category'){
                return $term->slug !== 'featured';
            }
            return true;
        });
    }
    return $terms;
});

Give it a try and let me know.

Source Link

I'm not sure I got it right but the following snippet should exclude the featured category from displaying from most of the front-end.

add_filter('get_object_terms', function (array $terms) {
    if (!is_admin()){
        $terms = array_filter($terms, function ($term) {
            return $term->taxonomy === 'category' && $term->slug !== 'featured';
        });
    }
    return $terms;
});

Give it a try and let me know.