You’ll need to rely on the global post variable, or get_post()
, which is essentially the same thing.
add_filter(
'the_content',
function( $content ) {
$post = get_post();
if ( in_the_loop() && has_category( 123, $post ) ) {
// etc.
}
return $content;
}
);
I included a check for in_the_loop()
, because the the_content
filter is commonly applied outside the loop in contexts where there won’t necessarily be a relevant global $post
variable.