Filter should modify the given value and return it. It should not print anything.
But your foreach loop does exactly opposite – it prints its output and doesn’t append anything to result. So when you use it to append its result to the content, it prints its result and doesn’t return anything – so nothing gets appended.
One way to fix it is to use buffering:
function one( $arr ) {
ob_start();
global $post;
$args = array(
'post_type' => 'custom-post-type',
'posts_per_page' => -1,
);
$customposts = get_posts( $args );
foreach ( $customposts as $post ) : setup_postdata( $post ); ?>
<div class="custom-post-listing">
<a href="https://wordpress.stackexchange.com/questions/339622/<?php the_permalink(); ?>"><?php the_title(); ?></a>
<p><?php the_date(); ?></p>
</div>
<?php endforeach; wp_reset_postdata();
return ob_get_clean();
}
Another, a little bit cleaner is to modify this function in such way, that it constructs strings as a result.