In your code, you store the images in the wp_options
table with the key category_images
, but there is nothing that tells WordPress that it must fetch the image when loading the taxonomy term (your category).
What you can do is either use get_option('category_images')
whenever you need to fetch the image, or add a hook filter like that.
add_filter( 'get_term', function ( WP_Term $_term, string $taxonomy ): WP_Term
{
if ( 'my_taxonomy_name' === $taxonomy ) {
$images = get_option( 'category_images' );
if ( $image = ( $images[ $_term->term_id ] ?? null ) ) {
$_term->background_image = $image;
}
}
return $_term;
}, 10, 2 );
You will then have the background_image
property added when you fetch your taxonomy term.