Function Reference: geodir_sc_popular_in_neighbourhood

Global Values

$wpdb
(object) (required) WordPress Database object.

Default: None

Parameters

($atts) (required)

Default: None

Return Values

(string)

    Filters

    ‘geodir_template_part-listing-listview’ [Line: 407]

    Source File

    geodir_sc_popular_in_neighbourhood() is located in geodir_location_manager/geodir_location_shortcodes.php [Line: 266]

    Source Code

    function geodir_sc_popular_in_neighbourhood( $atts ) {
    	ob_start();
    	$defaults = array(
    		'post_type'           => 'gd_place',
    		'category'            => '0',
    		'list_sort'           => 'latest',
    		'post_number'         => 5,
    		'layout'              => 'gridview_onehalf',
    		'character_count'     => 20,
    		'add_location_filter' => 1, // Not used
    	);
    
    	$params = shortcode_atts( $defaults, $atts );
    
    	/**
    	 * Being validating $params
    	 */
    
    	// Check we have a valid post_type
    	if ( ! ( gdsc_is_post_type_valid( $params['post_type'] ) ) ) {
    		$params['post_type'] = 'gd_place';
    	}
    
    	// Manage the entered categories
    	if ( 0 != $params['category'] || '' != $params['category'] ) {
    		$params['category'] = gdsc_manage_category_choice( $params['post_type'], $params['category'] );
    	}
    
    	// Validate our sorting choice
    	$params['list_sort'] = gdsc_validate_sort_choice( $params['list_sort'] );
    
    	// Post_number needs to be a positive integer
    	$params['post_number'] = absint( $params['post_number'] );
    	if ( 0 == $params['post_number'] ) {
    		$params['post_number'] = 1;
    	}
    
    	// Validate our layout choice
    	// Outside of the norm, I added some more simple terms to match the existing
    	// So now I just run the switch to set it properly.
    	$params['layout'] = gdsc_validate_layout_choice( $params['layout'] );
    
    	// Validate character_count
    	$params['character_count'] = absint( $params['character_count'] );
    	if ( 20 > $params['character_count'] ) {
    		$params['character_count'] = 20;
    	}
    
    	/**
    	 * End validation
    	 */
    
    	global $wpdb, $post, $geodir_post_type;
    
    	if ( $geodir_post_type == '' ) {
    		$geodir_post_type = 'gd_place';
    	}
    
    	$all_postypes = geodir_get_posttypes();
    
    	$location_id = '';
    
    	$not_in_array = array();
    
    	if ( geodir_is_page( 'detail' ) || geodir_is_page( 'preview' ) || geodir_is_page( 'add-listing' ) ) {
    
    		if ( isset( $post->post_type ) && $post->post_type == $params['post_type'] && isset( $post->post_location_id ) ) {
    
    			$not_in_array[] = $post->ID;
    
    			$location_id = $post->post_location_id;
    
    		}
    
    	} elseif ( in_array( $geodir_post_type, $all_postypes ) && $geodir_post_type == $params['post_type'] ) {
    
    		if ( isset( $_SESSION['gd_city'] ) && $_SESSION['gd_city'] != '' ) {
    
    			$location_id = $wpdb->get_var( $wpdb->prepare( "SELECT location_id FROM " . POST_LOCATION_TABLE . " WHERE city_slug = %s", array( $_SESSION['gd_city'] ) ) );
    
    		} else {
    
    			$default_location = geodir_get_default_location();
    			$location_id      = $default_location->location_id;
    
    		}
    
    	}
    
    	$gd_neighbourhoods = geodir_get_neighbourhoods( $location_id );
    
    	if ( $gd_neighbourhoods ) {
    		?>
    
    		
    hood_slug; } } $query_args = array( 'posts_per_page' => $params['post_number'], 'is_geodir_loop' => true, 'post__not_in' => $not_in_array, 'gd_neighbourhood' => $hood_slug_arr, 'gd_location' => ( $params['add_location_filter'] ) ? true : false, 'post_type' => $params['post_type'], 'order_by' => $params['list_sort'], 'excerpt_length' => $params['character_count'], ); if ( $params['category'] != 0 || $params['category'] != '' ) { $category_taxonomy = geodir_get_taxonomies( $params['post_type'] ); $tax_query = array( 'taxonomy' => $category_taxonomy[0], 'field' => 'id', 'terms' => $params['category'] ); $query_args['tax_query'] = array( $tax_query ); } global $gridview_columns; query_posts( $query_args ); if ( strstr( $params['layout'], 'gridview' ) ) { $listing_view_exp = explode( '_', $params['layout'] ); $gridview_columns = $params['layout']; $layout = $listing_view_exp[0]; } $template = apply_filters( "geodir_template_part-listing-listview", geodir_plugin_path() . '/geodirectory-templates/listing-listview.php' ); include( $template ); wp_reset_query(); ?>