As your hook only passes the $post_content
and $attachment_id
, you’ll first need to get the relevant post, and then you can output your required data.
Please try this and comment if it does not meet your requirements.
function myprefix_change_afip_post_content( $post_content, $attachment_id ) {
global $post
$post = get_post( $attachment_id );
setup_postdata( $post );
$my_uploaded_image = wp_get_attachment_image_src( $attachment_id );
$post_content = sprintf(
'This post – %1$s is uploaded by %2$s on %3$s on category %4$s',
get_the_title(),
get_the_author_meta( 'display_name' );
get_the_date(),
get_the_category()
);
wp_reset_postdata()
return $post_content;
}
Note – this will overwrite the previous $post_content
. If you want to add to it instead simply replace $post_content = sprintf(
with $post_content.= sprintf(
.