Skip to content

Instantly share code, notes, and snippets.

@FernandoSalinas33
Created July 30, 2018 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FernandoSalinas33/a27e70ad5030dbcdbaf663b3760a71d4 to your computer and use it in GitHub Desktop.
Save FernandoSalinas33/a27e70ad5030dbcdbaf663b3760a71d4 to your computer and use it in GitHub Desktop.
Add # of reviews a listing has on the listing card
add_filter( 'listify_get_listing_to_array', function( $data, $listing ) {
$count = get_comments_number( $listing->get_id() );
// Only add if our custom field is not empty.
if ( '' !== $count ) {
if($count == 1){$data['countz'] = $count ." Review";}
else{ $data['countz'] = $count ." Reviews";}
}
// Return modified list of data.
return $data;
}, 10, 2 );
add_action( 'listify_content_job_listing_footer', function() {
// Check if available.
echo '<# if ( data.countz ) { #>';
// Output inside a <div>
echo '<div class="my-countz-field">Total Reviews: {{data.countz}}</div>';
// End check.
echo '<# } #>';
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment