Guest User

Untitled

a guest
Jul 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. function profile_view(){
  2. $user_id = $_GET["user_id"]; // name of hidden input
  3.  
  4. $args = array(
  5. 'post_type' => 'listings',
  6. 'post_status' => 'publish',
  7. 'meta_query' => array(
  8. array(
  9. 'key' => 'stm_car_user',
  10. 'value' => $user_id
  11. ),
  12. array(
  13. 'key' => 'car_mark_as_sold',
  14. 'value' => '',
  15. 'compare' => 'NOT EXISTS'
  16. )
  17. )
  18. );
  19.  
  20. $query = new WP_Query($args);
  21.  
  22. $response = array();
  23.  
  24. //Grid/list settings
  25. $view_list = '';
  26. $view_grid = '';
  27. $view_map = '';
  28. $current_link_args = array();
  29. if(!empty($_GET)){
  30. $current_link_args = $_GET;
  31. }
  32.  
  33. $view_list_link = $view_grid_link = $view_map_link = $current_link_args;
  34. $view_list_link['view_type'] = 'list';
  35. $view_grid_link['view_type'] = 'grid';
  36. $view_map_link['view_type'] = 'map';
  37.  
  38.  
  39. if(!empty($_GET['view_type'])) {
  40. if ( $_GET['view_type'] == 'list' ) {
  41. $view_list = 'active';
  42. } elseif ( $_GET['view_type'] == 'grid' ) {
  43. $view_grid = 'active';
  44. $current_link_args['view_type'] = 'grid';
  45. }
  46. elseif ( $_GET['view_type'] == 'map' ) {
  47. $view_map = 'active';
  48. $current_link_args['view_type'] = 'map';
  49. }
  50. } else {
  51. $view_list = 'active';
  52. }
  53.  
  54.  
  55.  
  56.  
  57. if ( $query->have_posts() ):
  58. ob_start();
  59.  
  60. $template = 'partials/listing-cars/listing-list-profile-directory-loop';
  61. if(!empty($_GET['view_type']) and $_GET['view_type'] == 'grid') {
  62.  
  63. $template = 'partials/listing-cars/listing-grid-directory-loop';
  64.  
  65. } elseif(!empty($_GET['view_type']) and $_GET['view_type'] == 'map') {
  66.  
  67. $template = 'partials/listing-cars/listing-map';
  68.  
  69. } else {
  70.  
  71. $template = 'partials/listing-cars/listing-list-profile-directory-loop';
  72.  
  73. }
  74.  
  75.  
  76. while ( $query->have_posts() ) {
  77. $query->the_post();
  78. get_template_part($template);
  79.  
  80. }
  81.  
  82. $response['html'] = ob_get_contents();
  83. ob_end_clean();
  84. else:
  85.  
  86. endif;
  87. wp_reset_postdata();
  88.  
  89. $show_pagination = true;
  90. if(!empty($query->found_posts) and !empty($query->query_vars['posts_per_page'])) {
  91. if($query->found_posts < $query->query_vars['posts_per_page']) {
  92. $show_pagination = false;
  93. }
  94. }
  95.  
  96.  
  97.  
  98. $response = json_encode( $response );
  99.  
  100. echo $response;
  101. exit;
  102. }
  103.  
  104. add_action( 'rest_api_init', function () {
  105. register_rest_route( 'profile_view/v2', '/posts/(?P<id>d+)', array(
  106. 'methods' => 'GET',
  107. 'callback' => 'profile_view'
  108. ));
  109. });
  110. //add_action('wp_ajax_profile_view' , 'profile_view');
  111. //add_action('wp_ajax_nopriv_profile_view','profile_view');
Add Comment
Please, Sign In to add comment