Function Reference: geodir_get_recent_reviews

Summary

Returns the recent reviews.

Global Values

$wpdb
(object) (required) WordPress Database object.

Default: None
$gd_session
(object) (required) GeoDirectory Session object.

Default: None

Package

GeoDirectory

Parameters

$g_size
(int) (optional) Avatar size in pixels.

Default: 60
$no_comments
(int) (optional) Number of reviews you want to display.

Default: : 10
$comment_lenth
(int) (optional) Maximum number of characters you want to display. After that read more link
will appear.

Default: None
$show_pass_post
(bool) (optional) Not yet implemented.

Default: None

Return Values

(string)
  • Returns the recent reviews html.

Change Log

Since: 1.0.0

1.6.21 Recent reviews doesn’t working well with WPML.

Filters

‘geodir_reviewer_content_author_link’ [Line: 2107]

Source File

geodir_get_recent_reviews() is located in geodirectory-functions/custom_functions.php [Line: 1989]

Source Code

function geodir_get_recent_reviews( $g_size = 60, $no_comments = 5, $comment_lenth = 60, $show_pass_post = false ) {
	global $wpdb, $tablecomments, $tableposts, $rating_table_name, $gd_session, $table_prefix;
	$tablecomments = $wpdb->comments;
	$tableposts    = $wpdb->posts;

	$comments_echo  = '';
	$city_filter    = '';
	$region_filter  = '';
	$country_filter = '';

	if ( $gd_session->get( 'gd_multi_location' ) ) {
		if ( $gd_ses_country = $gd_session->get( 'gd_country' ) ) {
			$country_filter = $wpdb->prepare( " AND r.post_country=%s ", str_replace( "-", " ", $gd_ses_country ) );
		}

		if ( $gd_ses_region = $gd_session->get( 'gd_region' ) ) {
			$region_filter = $wpdb->prepare( " AND r.post_region=%s ", str_replace( "-", " ", $gd_ses_region ) );
		}

		if ( $gd_ses_city = $gd_session->get( 'gd_city' ) ) {
			$city_filter = $wpdb->prepare( " AND r.post_city=%s ", str_replace( "-", " ", $gd_ses_city ) );
		}
	}

	$join = '';
	$where = '';

	if (geodir_is_wpml()) {
		$lang_code = ICL_LANGUAGE_CODE;

		if ($lang_code) {
			$join .= " JOIN " . $table_prefix . "icl_translations AS icltr2 ON icltr2.element_id = c.comment_post_ID AND p.ID = icltr2.element_id AND CONCAT('post_', p.post_type) = icltr2.element_type LEFT JOIN " . $table_prefix . "icl_translations AS icltr_comment ON icltr_comment.element_id = c.comment_ID AND icltr_comment.element_type = 'comment'";
			$where .= " AND icltr2.language_code = '" . $lang_code . "' AND (icltr_comment.language_code IS NULL OR icltr_comment.language_code = icltr2.language_code)";
		}
	}

	$request = "SELECT r.id AS ID, r.post_type, r.comment_id AS comment_ID, r.post_date AS comment_date, r.overall_rating, r.user_id, r.post_id FROM " . GEODIR_REVIEW_TABLE . " AS r JOIN " . $wpdb->comments . " AS c ON c.comment_ID = r.comment_id JOIN " . $wpdb->posts . " AS p ON p.ID = c.comment_post_ID " . $join . " WHERE c.comment_parent = 0 AND c.comment_approved = 1 AND r.status = 1 AND r.overall_rating >= 1 AND p.post_status = 'publish' " . $where . " ORDER BY r.post_date DESC, r.id DESC LIMIT ". $no_comments;

	$comments = $wpdb->get_results( $request );

	foreach ( $comments as $comment ) {
		// Set the extra comment info needed.
		$comment_extra = $wpdb->get_row( "SELECT * FROM $wpdb->comments WHERE comment_ID =$comment->comment_ID" );
		$comment->comment_content      = $comment_extra->comment_content;
		$comment->comment_author       = $comment_extra->comment_author;
		$comment->comment_author_email = $comment_extra->comment_author_email;

		$comment_id      = '';
		$comment_id      = $comment->comment_ID;
		$comment_content = strip_tags( $comment->comment_content );

		$comment_content = preg_replace( '#(\\[img\\]).+(\\[\\/img\\])#', '', $comment_content );

		$permalink            = get_permalink( $comment->ID ) . "#comment-" . $comment->comment_ID;
		$comment_author_email = $comment->comment_author_email;
		$comment_post_ID      = $comment->post_id;

		$post_title        = get_the_title( $comment_post_ID );
		$permalink         = get_permalink( $comment_post_ID );
		$comment_permalink = $permalink . "#comment-" . $comment->comment_ID;
		$read_more         = '' . __( 'Read more', 'geodirectory' ) . '';

		$comment_content_length = strlen( $comment_content );
		if ( $comment_content_length > $comment_lenth ) {
			$comment_excerpt = geodir_utf8_substr( $comment_content, 0, $comment_lenth ) . '... ' . $read_more;
		} else {
			$comment_excerpt = $comment_content;
		}

		if ( $comment->user_id ) {
			$user_profile_url = get_author_posts_url( $comment->user_id );
		} else {
			$user_profile_url = '';
		}

		if ( $comment_id ) {
			$comments_echo .= '
  • '; $comments_echo .= ""; if ( function_exists( 'get_avatar' ) ) { if ( ! isset( $comment->comment_type ) ) { if ( $user_profile_url ) { $comments_echo .= ''; } $comments_echo .= get_avatar( $comment->comment_author_email, $g_size, geodir_plugin_url() . '/geodirectory-assets/images/gravatar2.png' ); if ( $user_profile_url ) { $comments_echo .= ''; } } elseif ( ( isset( $comment->comment_type ) && $comment->comment_type == 'trackback' ) || ( isset( $comment->comment_type ) && $comment->comment_type == 'pingback' ) ) { if ( $user_profile_url ) { $comments_echo .= ''; } $comments_echo .= get_avatar( $comment->comment_author_url, $g_size, geodir_plugin_url() . '/geodirectory-assets/images/gravatar2.png' ); } } elseif ( function_exists( 'gravatar' ) ) { if ( $user_profile_url ) { $comments_echo .= ''; } $comments_echo .= "comment_type ) { $comments_echo .= gravatar( $comment->comment_author_email, $g_size, geodir_plugin_url() . '/geodirectory-assets/images/gravatar2.png' ); if ( $user_profile_url ) { $comments_echo .= ''; } } elseif ( ( 'trackback' == $comment->comment_type ) || ( 'pingback' == $comment->comment_type ) ) { if ( $user_profile_url ) { $comments_echo .= ''; } $comments_echo .= gravatar( $comment->comment_author_url, $g_size, geodir_plugin_url() . '/geodirectory-assets/images/gravatar2.png' ); if ( $user_profile_url ) { $comments_echo .= ''; } } $comments_echo .= "\" alt=\"\" class=\"avatar\" />"; } $comments_echo .= "\n"; $comments_echo .= ''; $author_link = apply_filters('geodir_reviewer_content_author_link', true); if ( $comment->user_id && $author_link ) { $comments_echo .= ''; } $comments_echo .= '' . $comment->comment_author . ' '; if ( $comment->user_id && $author_link ) { $comments_echo .= ''; } $comments_echo .= '' . __( 'reviewed', 'geodirectory' ) . ' '; $comments_echo .= '' . $post_title . ''; $comments_echo .= geodir_get_rating_stars( $comment->overall_rating, $comment_post_ID ); $comments_echo .= '

    ' . $comment_excerpt . ''; //echo preg_replace('#(\\[img\\]).+(\\[\\/img\\])#', '', $comment_excerpt); $comments_echo .= '

    '; $comments_echo .= "
    \n"; $comments_echo .= '
  • '; } } return $comments_echo; }