$locations_settings['orderby'],
'order' => $locations_settings['order'],
'hide_empty' => ! empty( $locations_settings['hide_empty'] ) ? 1 : 0,
'parent' => max( 0, $general_settings['base_location'] ),
'hierarchical' => false
);
$terms = get_terms( 'acadp_locations', $args );
if( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
ob_start();
include( acadp_get_template( "locations/acadp-public-locations-display.php" ) );
return ob_get_clean();
}
}
return ''.__( 'No Results Found.', 'advanced-classifieds-and-directory-pro' ).'';
}
/**
* Run the shortcode [acadp_location].
*
* @since 1.0.0
* @access public
*
* @params array $atts an associative array of attributes.
*/
public function run_shortcode_location( $atts ) {
$shortcode = 'acadp_location';
$general_settings = get_option( 'acadp_general_settings' );
$has_location = empty( $general_settings['has_location'] ) ? false : true;
$term_slug = '';
if( $has_location ) {
$term_slug = get_query_var( 'acadp_location' );
if( '' == $term_slug && ! empty( $atts['id'] ) ) {
$term = get_term_by( 'id', (int) $atts['id'], 'acadp_locations' );
$term_slug = $term->slug;
}
}
if( '' != $term_slug ) {
$listings_settings = get_option( 'acadp_listings_settings' );
$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
// Enqueue style dependencies
wp_enqueue_style( ACADP_PLUGIN_NAME );
// Enqueue script dependencies
if( wp_script_is( ACADP_PLUGIN_NAME.'-bootstrap', 'registered' ) ) {
wp_enqueue_script( ACADP_PLUGIN_NAME.'-bootstrap' );
}
wp_enqueue_script( ACADP_PLUGIN_NAME );
// ...
$can_show_header = empty( $listings_settings['display_in_header'] ) ? false : true;
$can_show_listings_count = $can_show_header && in_array( 'listings_count', $listings_settings['display_in_header'] ) ? true : false;
$can_show_views_selector = $can_show_header && in_array( 'views_selector', $listings_settings['display_in_header'] ) ? true : false;
$can_show_orderby_dropdown = $can_show_header && in_array( 'orderby_dropdown', $listings_settings['display_in_header'] ) ? true : false;
$can_show_date = isset( $listings_settings['display_in_listing'] ) && in_array( 'date', $listings_settings['display_in_listing'] ) ? true : false;
$can_show_user = isset( $listings_settings['display_in_listing'] ) && in_array( 'user', $listings_settings['display_in_listing'] ) ? true : false;
$can_show_category = isset( $listings_settings['display_in_listing'] ) && in_array( 'category', $listings_settings['display_in_listing'] ) ? true : false;
$can_show_views = isset( $listings_settings['display_in_listing'] ) && in_array( 'views', $listings_settings['display_in_listing'] ) ? true : false;
$can_show_images = empty( $general_settings['has_images'] ) ? false : true;
$sort_by_featured = empty( $featured_listing_settings['enabled'] ) ? false : true;
$current_order = isset( $_GET['order'] ) ? $_GET['order'] : ( $listings_settings['orderby'].'-'.$listings_settings['order'] );
$has_price = empty( $general_settings['has_price'] ) ? false : true;
$can_show_price = false;
if( $has_price ) {
$can_show_price = isset( $listings_settings['display_in_listing'] ) && in_array( 'price', $listings_settings['display_in_listing'] ) ? true : false;
}
$can_show_location = false;
if( $has_location ) {
$can_show_location = isset( $listings_settings['display_in_listing'] ) && in_array( 'location', $listings_settings['display_in_listing'] ) ? true : false;
}
$span = 12;
if( $can_show_images ) $span = $span - 2;
if( $can_show_price ) $span = $span - 3;
$span_middle = 'col-md-'.$span;
// Define the query
$paged = ( get_query_var('paged') ) ? absint( get_query_var('paged') ) : 1;
$args = array(
'post_type' => 'acadp_listings',
'posts_per_page' => ! empty( $listings_settings['listings_per_page'] ) ? $listings_settings['listings_per_page'] : -1,
'paged' => $paged,
);
if( $has_location ) {
$args['tax_query'] = array(
array(
'taxonomy' => 'acadp_locations',
'field' => 'slug',
'terms' => $term_slug,
'include_children' => isset( $listings_settings['include_results_from'] ) && in_array( 'child_locations', $listings_settings['include_results_from'] ) ? true : false,
),
);
}
switch( $current_order ) {
case 'title-asc' :
if( $sort_by_featured ) {
$args['meta_key'] = 'featured';
$args['orderby'] = array(
'meta_value_num' => 'DESC',
'title' => 'ASC',
);
} else {
$args['orderby'] = 'title';
$args['order'] = 'ASC';
};
break;
case 'title-desc' :
if( $sort_by_featured ) {
$args['meta_key'] = 'featured';
$args['orderby'] = array(
'meta_value_num' => 'DESC',
'title' => 'DESC',
);
} else {
$args['orderby'] = 'title';
$args['order'] = 'DESC';
};
break;
case 'date-asc' :
if( $sort_by_featured ) {
$args['meta_key'] = 'featured';
$args['orderby'] = array(
'meta_value_num' => 'DESC',
'date' => 'ASC',
);
} else {
$args['orderby'] = 'date';
$args['order'] = 'ASC';
};
break;
case 'date-desc' :
if( $sort_by_featured ) {
$args['meta_key'] = 'featured';
$args['orderby'] = array(
'meta_value_num' => 'DESC',
'date' => 'DESC',
);
} else {
$args['orderby'] = 'date';
$args['order'] = 'DESC';
};
break;
case 'price-asc' :
if( $sort_by_featured ) {
$args['meta_query'] = array(
'relation' => 'AND',
'featured' => array(
'key' => 'featured',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
'price' => array(
'key' => 'price',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
);
$args['orderby'] = array(
'featured' => 'DESC',
'price' => 'ASC',
);
} else {
$args['meta_key'] = 'price';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'ASC';
};
break;
case 'price-desc' :
if( $sort_by_featured ) {
$args['meta_query'] = array(
'relation' => 'AND',
'featured' => array(
'key' => 'featured',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
'price' => array(
'key' => 'price',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
);
$args['orderby'] = array(
'featured' => 'DESC',
'price' => 'DESC',
);
} else {
$args['meta_key'] = 'price';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'DESC';
};
break;
case 'views-asc' :
if( $sort_by_featured ) {
$args['meta_query'] = array(
'relation' => 'AND',
'featured' => array(
'key' => 'featured',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
'views' => array(
'key' => 'views',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
);
$args['orderby'] = array(
'featured' => 'DESC',
'views' => 'ASC',
);
} else {
$args['meta_key'] = 'views';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'ASC';
};
break;
case 'views-desc' :
if( $sort_by_featured ) {
$args['meta_query'] = array(
'relation' => 'AND',
'featured' => array(
'key' => 'featured',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
'views' => array(
'key' => 'views',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
);
$args['orderby'] = array(
'featured' => 'DESC',
'views' => 'DESC',
);
} else {
$args['meta_key'] = 'views';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'DESC';
};
break;
}
$acadp_query = new WP_Query( $args );
// Start the Loop
global $post;
// Process output
if( $acadp_query->have_posts() ) {
$view = acadp_get_listings_current_view_name();
ob_start();
include( acadp_get_template( "listings/acadp-public-listings-$view-display.php" ) );
wp_reset_postdata(); // Use reset postdata to restore orginal query
return ob_get_clean();
}
}
return ''.__( 'No Results Found.', 'advanced-classifieds-and-directory-pro' ).'';
}
}