$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>categories - Hide specific category link from showing|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

categories - Hide specific category link from showing

matteradmin9PV0评论

I have a category that is used for internal purposes. It's "Key Articles" (slug: key-articles; ID: 47).

I don't want this showing up anywhere in the site that the category taxonomy is displayed (in the post meta, in posts by category widget, etc.).

I've attempted the solution found here, using the code below, but it oddly removed the the very first category on each post, not the one I have specified. I tried using the slug, ID, and category name. Same result each time.

add_filter('get_the_terms', 'hide_categories_terms', 10, 3);
function hide_categories_terms($terms, $post_id, $taxonomy){

// get term to exclude by name, by id or maybe by slug
$exclude = get_term_by('slug', 'key-articles', 'category', ARRAY_A);

if (!is_admin()) {
    foreach($terms as $key => $term){
        if($term->taxonomy == "category"){
            if(in_array($key, $exclude)) unset($terms[$key]);
        }
    }
}
return $terms;
}

I found that solution here, where I also tried other solutions offered there, such as this one. No luck.

I am thinking newer versions of WordPress might have changed such that these methods are now useless.

What's the best way to go about it?

Post a comment

comment list (0)

  1. No comments so far