• I need to display the list of locations from a listing using a shortcode within a custom content area. What PHP function can I use in my functions.php to throw the list of listing locations into the shortcode?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Mahfuzul Alam

    (@mahfuz87)

    Hi @fan297

    Thank you for reaching out.

    You can use the following custom code to create the shortcode ([directorist_single_locations]) –

    add_shortcode('directorist_single_locations', function () {
    
    	ob_start();
    
    	$term_list = [];
    	$listing_id = get_the_ID();
    	$directory_type = 'general';
    
    	$locations = get_the_terms($listing_id, ATBDP_LOCATION);
    	$directory_types = get_the_terms($listing_id, ATBDP_DIRECTORY_TYPE);
    
    	if ($directory_types && count($directory_types) > 0) {
    		$directory_type = $directory_types[0]->slug;
    	}
    
    	if ($locations && count($locations) > 0) {
    		foreach ($locations as $location) {
    			$term_list[] = $location->slug;
    		}
    	}
    
    	if (!empty($term_list) && count($term_list) > 0) {
    		echo do_shortcode('[directorist_all_locations slug="' . implode(',', $term_list) . '" directory_type="' . $directory_type . '" view="grid"]');
    	}
    
    	return ob_get_clean();
    });

    Then use the Custom Content field to display the shortcode. You must get something similar to this result > https://prnt.sc/zVaKt4MTbC-l

    Please let me know if you need further assistance.

    Kind Regards

    Thread Starter Fabio Nogueira

    (@fan297)

    Worked, thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get location list in Shortcode’ is closed to new replies.