Merge facetwp listing query with co-authors plus for author archives

<?php
/**
 * Set author_name for a FacetWP Listing Builder listing template query on a author archive page
 * for compatibility with co-authors plus https://wordpress.org/plugins/co-authors-plus/
 * Change 'my_author_listing' in ln 9 to name of the facetwp listing you are using in the author archive
 * See: https://facetwp.com/help-center/using-facetwp-with/co-authors-plus/#using-a-listing-builder-listing-in-an-author-archive
 */

add_filter( 'facetwp_query_args', function( $query_args, $class ) {
  if ( 'my_author_listing' == $class->ajax_params['template'] ) { // Change 'my_author_listing' to name of the listing you are using in the author archive
  $uri_parts = explode( '/', $class->ajax_params['http_params']['uri'] ); // On refresh get author_name from last part of FWP uri
    $query_args['author_name'] = ! empty( get_query_var( 'author_name' ) )
    ? get_query_var( 'author_name' )
    : array_pop( $uri_parts );
  }
  return $query_args;
}, 10, 2 );