Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function profile_view(){
- $user_id = $_GET["user_id"]; // name of hidden input
- $args = array(
- 'post_type' => 'listings',
- 'post_status' => 'publish',
- 'meta_query' => array(
- array(
- 'key' => 'stm_car_user',
- 'value' => $user_id
- ),
- array(
- 'key' => 'car_mark_as_sold',
- 'value' => '',
- 'compare' => 'NOT EXISTS'
- )
- )
- );
- $query = new WP_Query($args);
- $response = array();
- //Grid/list settings
- $view_list = '';
- $view_grid = '';
- $view_map = '';
- $current_link_args = array();
- if(!empty($_GET)){
- $current_link_args = $_GET;
- }
- $view_list_link = $view_grid_link = $view_map_link = $current_link_args;
- $view_list_link['view_type'] = 'list';
- $view_grid_link['view_type'] = 'grid';
- $view_map_link['view_type'] = 'map';
- if(!empty($_GET['view_type'])) {
- if ( $_GET['view_type'] == 'list' ) {
- $view_list = 'active';
- } elseif ( $_GET['view_type'] == 'grid' ) {
- $view_grid = 'active';
- $current_link_args['view_type'] = 'grid';
- }
- elseif ( $_GET['view_type'] == 'map' ) {
- $view_map = 'active';
- $current_link_args['view_type'] = 'map';
- }
- } else {
- $view_list = 'active';
- }
- if ( $query->have_posts() ):
- ob_start();
- $template = 'partials/listing-cars/listing-list-profile-directory-loop';
- if(!empty($_GET['view_type']) and $_GET['view_type'] == 'grid') {
- $template = 'partials/listing-cars/listing-grid-directory-loop';
- } elseif(!empty($_GET['view_type']) and $_GET['view_type'] == 'map') {
- $template = 'partials/listing-cars/listing-map';
- } else {
- $template = 'partials/listing-cars/listing-list-profile-directory-loop';
- }
- while ( $query->have_posts() ) {
- $query->the_post();
- get_template_part($template);
- }
- $response['html'] = ob_get_contents();
- ob_end_clean();
- else:
- endif;
- wp_reset_postdata();
- $show_pagination = true;
- if(!empty($query->found_posts) and !empty($query->query_vars['posts_per_page'])) {
- if($query->found_posts < $query->query_vars['posts_per_page']) {
- $show_pagination = false;
- }
- }
- $response = json_encode( $response );
- echo $response;
- exit;
- }
- add_action( 'rest_api_init', function () {
- register_rest_route( 'profile_view/v2', '/posts/(?P<id>d+)', array(
- 'methods' => 'GET',
- 'callback' => 'profile_view'
- ));
- });
- //add_action('wp_ajax_profile_view' , 'profile_view');
- //add_action('wp_ajax_nopriv_profile_view','profile_view');
Add Comment
Please, Sign In to add comment