Thanks to tck30’s comment, I figured it out.
For reference, I needed to add “$query->post->ID”.
Working code:
add_filter('ajax_wpqsf_reoutput', 'customize_output', '', 4);
function customize_output($results , $arg, $id, $getdata ){
// The Query
$apiclass = new ajaxwpqsfclass();
$query = new WP_Query( $arg );
ob_start(); //$results ='';
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>'.get_permalink().'</li>';
echo '<li>'.get_post_meta( $query->post->ID, 'course2_title', true).'</li>';
}
echo $apiclass->ajax_pagination($arg['paged'],$query->max_num_pages, 4, $id);
} else {
echo 'No se han encontrado resultados.';
}
/* Restore original Post Data */
wp_reset_postdata();
$results = ob_get_clean();
return $results;
}