Jump to content

Hide Listing based on Field Selection


JoshLewis

Recommended Posts

Trying to figure out the best way to hide listings based on a select field's value of 'private'. The following successfully sets listings as "Pending Moderation" in listings list view:

function list_page_hide_listings($listings, $params)
{
	foreach ($listings as & $listing)
	{

	if(!empty($listing['Field']['pairs']['jr_authorized']['value'][0])) {
			if($listing['Field']['pairs']['jr_private']['value'][0] == 'private') {
                  $listing['Listing']['state'] = 0;
                  $listing['Listing']['access'] = 0;
		}
	}
	return $listings;
}
 
Clickfwd\Hook\Filter::add('post_get_listings_listpage_query', 'list_page_hide_listings', 10);

I'm aware would have to work out other views as well. Alternatively could create a few overrides for list view, research results, and search module that only shows content if it's not set to 'private' by wrapping it with:

if($listing['Field']['pairs']['jr_private']['value'][0] != 'private'):

 

Link to comment
×
×
  • Create New...