Jump to content

Automatic Relations to Reviews


JoshLewis

Recommended Posts

Trying to create a filter for reviews to inherit the listing's relations so that if people view listings state/country/city/area, they could show the latest reviews in those listings.

function inherit_listing_parents($data, $wpdb)
{
	global $wpdb;
	$listing_id;
	$listing_id = $data['Review']['pid'];
	$table_name = $wpdb->prefix."jreviews_content";
	if(!empty($listing_id) {
		$results = $wpdb->get_row($wpdb->prepare("SELECT `jr_parents` FROM `".$table_name."` WHERE `contentid` = $listing_id", $listing_id));
	}
	
	/* Before assigning $results->jr_parents we should use a static value for confirming our ability to save review relations */
	$data['Field']['Review']['jr_ascentparents'][0] = "21";
	$data['__raw']['Field']['Review']['jr_ascentparents'][0] = "21";
    return $data;
}
 
Clickfwd\Hook\Filter::add('review_save_pre', 'inherit_listing_parents', 10);

There may be a security check on JReviews preventing $data['Field']['Review']['jr_ascentparents'][0] from saving. When using dd() function it shows "21" in the response with no extra spaces in the preferred syntax. Have also tried other variations such as "*21*". Can save values to a text field with no problems, but saving to relations is a bit trickier.

 

Edited by JoshLewis
Link to comment
×
×
  • Create New...