• Hi,

    I used this great plugin and would like to show the category I assigned in my post.
    I tried this code <?php the_category(); ?> and it will show all the categories instead the assigned one.
    How can I modify this code?

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • tdmalone’s solution is great, but I needed a small tweak to get it working:

    add_filter("get_the_categories","chr_primary_category");
    function chr_primary_category($cats){
    	global $post;
    	$chr_catmeta=get_post_meta($post->ID,"_category_permalink",true);
    	if($chr_catmeta=="") return $cats; // save our energy if there's no primary category set
    	$specialcat="";
    	foreach($cats as $key=>$cat){
    		if($cat->term_id==$chr_catmeta['category']){
    			$specialcat=$cat;
    			unset($cats[$key]);
    		}
    	}
    	if($specialcat!=""){
    		$cats=array_merge(array($specialcat),$cats); // merge it all back together, with our special category first
    	}
    	return $cats;
    }

    In my case, the chr_catmeta var was an array, so I needed to access it’s category member for the comparison to work.

    • This reply was modified 8 years, 1 month ago by neligajb.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show the category from permalink’ is closed to new replies.