Related listings by same author

How can I use a php snippet to write a code so that only listings from the same author of the listing are displayed from the listings in the “related listings” section? (I don’t want to show listings from all users)


Sorry, there’s no simple code snippet for this, it would require a custom implementation. If customizations beyond the available features are required for your site, please consider hiring someone for custom work

1 Like

@andrii Hello, Could you please tell me in which php file (path) or with which hook to solve this?

@andrii @ihor Am trying this but isnt work :frowning:

remove_action( 'hivepress/v1/models/listing/relate', 'existing_function_name' );

	function( $query, $listing ) {
		$query->filter( [ 'user' => $listing->get_user_id() ] );

Sorry for the delay. The snippet is actually ok, please try replacing this:




Accessing fields (e.g. “id”) of the related models (“user”) requires a double underscore.

If it still doesn’t work please try to check the $listing->get_user_id() value, the $listing, etc. using var_dump or error_log.

thx but doesnt work

Please try debugging this further because the snippet seems to be ok, e.g. add echo123;die(); to the callback to check if it runs at all on the listing page, if so then you can var_dump the values in the callback and check the query itself via var_dump($query->get_args());

Unfortunately, I’m not good enough at programming to handle debugging
All I know is that on the listing page after adding my code, no similar listings are shown at all


Unfortunately, we can’t help with debugging, so if you need help, I recommend hiring an expert: Experts | HivePress