Support » Plugin: Classified Listing – Classified ads & Business Directory Plugin » Related listing from same location and same category

  • Resolved turansaim

    (@turansaim)


    Hi is there any setting that I can show related listings from the same location and same category? Now it only shows new listings. For example I have hotels, businesses as listing type and New York and San Francisco as a location. When a person click on a hotel from New York I want to display other hotels from New York. How can we do this?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support Ali Akbar Reyad

    (@alireyad)

    Sorry, Don’t have setting for it. Right now, it shows from same category https://prnt.sc/DwSyntG7kEhm but you can get it from same category and same location by overriding related listing query.

    Thank You

    Thread Starter turansaim

    (@turansaim)

    Thank you for your answer. Can you provide me the codes to write? I dont know how to do that. Thank you.

    Plugin Support Ali Akbar Reyad

    (@alireyad)

    Okay. Add following code in your child theme functions.php file –

    add_filter( 'rtcl_related_listing_query_arg', function ( $query ) {
    	$listing = rtcl()->factory->get_listing( get_the_ID() );
    
    	if ( is_object( $listing ) ) {
    		$location = $listing->get_location_ids();
    
    		if ( ! empty( $location ) ) {
    			$query['tax_query'][]           = [
    				'taxonomy' => rtcl()->location,
    				'field'    => 'term_id',
    				'terms'    => end( $location )
    			];
    			$query['tax_query']['relation'] = 'AND';
    		}
    	}
    
    	return $query;
    } );
    Thread Starter turansaim

    (@turansaim)

    It works thank you very much. Is it possible to add a code to display from main category related listings from same category if the sub category doesnt have similar posts? For example I look for hotels in New York, Manhattan. There is no another listing from Manhattan to show as related but there are hotels in another Towns in New York. Can we do that too? Thank you!

    Plugin Support Ali Akbar Reyad

    (@alireyad)

    Yes, it’s also possible. Need to modify in few portion to do it.

    Do you want parent category and parent location for both?

    Thread Starter turansaim

    (@turansaim)

    If you can provide both it would be awesome. If the future maybe other users will need and grab it from here. I only need parent location for my site. Thank you for the support.

    • This reply was modified 3 months, 1 week ago by turansaim.
    Plugin Support Ali Akbar Reyad

    (@alireyad)

    Okay, will give the code.

    Thank You

    Thread Starter turansaim

    (@turansaim)

    I hope you will send it soon.
    Thank you for your help.

    Plugin Support Ali Akbar Reyad

    (@alireyad)

    Remove previous code and add following code –

    add_filter( 'rtcl_related_listing_query_arg', function ( $query ) {
    	$listing = rtcl()->factory->get_listing( get_the_ID() );
    
    	if ( is_object( $listing ) ) {
    		$location = $listing->get_location_ids();
    
    		if ( ! empty( $location ) ) {
    			$query['tax_query'][]           = [
    				'taxonomy' => rtcl()->location,
    				'field'    => 'term_id',
    				'terms'    => $location
    			];
    			$query['tax_query']['relation'] = 'AND';
    		}
    	}
    
    	return $query;
    } );

    https://prnt.sc/Oxe0eKlsyVQX

    Thread Starter turansaim

    (@turansaim)

    Yes, it works thank you very much for your help.

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.