Jump to content

Assign Listings to Specific User when submitting to Specified Category


JoshLewis

Recommended Posts

I have a listing category where it's ideal for new listings to go to a specific member, but want all other categories to keep the original author. Utilizing listing_save_pre this can be accomplished:

function assign_user($data, $params)
{
  // Check category id
  if ( $data['Listing']['catid'] == 6 ) {
    	$data['Listing']['created_by'] = 5; // assign listings created in catid 6 to user #5
  }
  return $data;
}
 
Clickfwd\Hook\Filter::add('listing_save_pre', 'assign_user', 10);

Other listing variables can be used for condition(s) to check and assign: https://www.jreviews.com/docs/theme-resources/discover-data-available-in-templates#listing-variables

Just be sure to use dd($data) and properly map out the arrays given slight differences in listing variables to $data[] array. Always test before actually saving the data which is another huge benefit of the dd() function. Reviews also have their own save pre, hence it's possible to do the same for reviews.

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Please refer to our Privacy Policy.