Created
July 30, 2018 21:36
-
-
Save FernandoSalinas33/a27e70ad5030dbcdbaf663b3760a71d4 to your computer and use it in GitHub Desktop.
Add # of reviews a listing has on the listing card
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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