[wp-hackers] Child categories

Jeremy Clarke jer at simianuprising.com
Thu Jan 30 15:29:02 UTC 2014


On Thu, Jan 23, 2014 at 9:24 AM, Dobri <dyordan1 at ramapo.edu> wrote:

>
> I think I'll look into filtering the standard taxonomy meta box content
> instead of creating my own so if someone has an idea if there are any hooks
> for that, that'd be helpful.
>
>
Based on past experiences the best/only place to control the output of the
categories box is actually pretty far down in the chain: get_terms()

Here's the filter and first line of the function I use (which
re-alphabetizes the list because I had an issue with Arabic text coming out
not in Arabic-alphabetical-order):

add_filter('get_terms', 'gv_filter_get_terms', 10, 3);
function gv_filter_get_terms($terms, $taxonomies, $args) {
   [...]
}

The main problem you'll have using this method is the need to very
explicitly avoid running your filter for cases other than the metabox. One
thing I found vital for this was testing to make sure that 'all' was set as
the 'fields' to retrieve:

if ('all' != $args['fields'])
return $terms;

If you don't have that check your code will choke when it does an 'ids'
query and your object-expecting code filters it into oblivion.

Since your code would probably be a lot more destructive than mine you
might want to consider more drastic measures, like inspecting the backtrace
chain (wp_debug_backtrace_summary()) for explicit confirmation that you're
filtering the content of the metabox.

Good luck,

-- 
Jeremy Clarke • jeremyclarke.org
Code and Design • globalvoicesonline.org


More information about the wp-hackers mailing list