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.