Return conditional category in load_posts_by_ajax

The AJAX handler doesn’t know anything about the page or context that the request was made from, so you’re going to need to send the category along with AJAX request, alongside the page number.

So you’re going to need to store the category name somewhere in the shortcode output, and then retrieve that with your JavaScript when sending the request. A data- attribute on the load more button would be a relatively straightforward way to do this:

'<div class="loadmore p-2 px-3 mx-auto museo-700" data-category="' . esc_attr( $category ) . '">Voir plus dʼactus</div>'

(Please consider making this a proper button element)

You haven’t included your JavaScript in the question, so I can’t make direct edits, but it would look something like this:

jQuery( '.loadmore' ).click( function( e ) {
    e.preventDefault();

    var $button = jQuery( this );
    var category = $button.data( 'category' ); // <-- Important bit.

    // Figure out page number etc.

    jQuery.post( {
        // Set URL, success handler, etc.
        data: {
            action: 'load_posts_by_ajax',
            page: page,
            category: category, // <-- Important bit.
        }
    } )
} );

(This type of request should really be a GET, not a POST.)

And then in your AJAX handler, use the passed value the same way you do in your original query:

if ( ! empty( $_POST['category'] ) ) {
    $args['category_name'] = $_POST['category'];
}

error code: 523