You’re using the correct code (get_taxonomy('dog')->object_type
) or function, but it should only be used after the taxonomy has been registered. Otherwise, the function would return a false
instead of a proper taxonomy object which contains properties like object_type
which is an array of post types registered for the taxonomy.
And because taxonomies are normally (or should be) registered during the init
hook, you can use any hooks that WordPress fires after the init
hook, e.g. wp_loaded
or in your case, you’d want to use the admin_init
which runs on the admin side of the site like the post editing screens:
add_action( 'admin_init', function () {
// Make sure the taxonomy exists.
if ( ! $tax = get_taxonomy( 'dog' ) ) {
return;
}
foreach ( $tax->object_type as $type ) {
add_filter( "manage_{$type}_posts_columns", 'update_dog_type_columns' );
add_action( "manage_{$type}_posts_custom_column", 'update_dog_type_column', 10, 2 );
}
} );