| @@ -124,9 +124,9 @@ | ||
| 124 | 124 | |
| 125 | 125 | $this->db->where($where); |
| 126 | 126 | |
| 127 | 127 | if(wdk_get_option('wdk_sub_listings_enable')) { |
| 128 | - $this->db->where(array('listing_parent_post_id IS NULL'=>NULL)); | |
| 128 | + $this->db->where(array('(listing_parent_post_id IS NULL OR listing_parent_post_id = 0)'=>NULL)); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | $this->db->order_by($this->_order_by); |
| 132 | 132 | |
| @@ -258,9 +258,9 @@ | ||
| 258 | 258 | $this->db->where($where); |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | if(wdk_get_option('wdk_sub_listings_enable')) { |
| 262 | - $this->db->where(array('listing_parent_post_id IS NULL'=>NULL)); | |
| 262 | + $this->db->where(array('(listing_parent_post_id IS NULL OR listing_parent_post_id = 0)'=>NULL)); | |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | $this->db->limit($limit); |
| 266 | 266 | $this->db->offset($offset); |
| @@ -334,9 +334,23 @@ | ||
| 334 | 334 | if(!$this->check_deletable($post_id, $user_id)) return false; |
| 335 | 335 | |
| 336 | 336 | $this->load->model('listingfield_m'); |
| 337 | 337 | $this->load->model('listingusers_m'); |
| 338 | + | |
| 339 | + /* remove images direct */ | |
| 340 | + if ( get_option('wdk_remove_direct_listing_images', false)) { | |
| 341 | + global $Winter_MVC_WDK; | |
| 342 | + $Winter_MVC_WDK->load_helper('listing'); | |
| 338 | 343 | |
| 344 | + $listing_images = wdk_field_value('listing_images', $post_id); | |
| 345 | + if(!empty($listing_images)) { | |
| 346 | + $image_ids = explode(',', $listing_images); | |
| 347 | + foreach ($image_ids as $key => $image_id) { | |
| 348 | + wp_delete_attachment($image_id, true); | |
| 349 | + } | |
| 350 | + } | |
| 351 | + } | |
| 352 | + | |
| 339 | 353 | /* remove listing */ |
| 340 | 354 | parent::delete($post_id); |
| 341 | 355 | $this->listingfield_m->delete($post_id); |
| 342 | 356 | $this->listingusers_m->delete($post_id); |
| @@ -343,8 +357,12 @@ | ||
| 343 | 357 | |
| 344 | 358 | /* remove post */ |
| 345 | 359 | wp_delete_post($post_id, true); |
| 346 | 360 | |
| 361 | + // Delete listing images if setting enabled | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 347 | 365 | do_action('wpdirectorykit/model/listing/delete', $post_id); |
| 348 | 366 | |
| 349 | 367 | return true; |
| 350 | 368 | |
| @@ -373,8 +391,17 @@ | ||
| 373 | 391 | $counter = intval(wdk_field_value('counter_views', $listing_id)); |
| 374 | 392 | } |
| 375 | 393 | |
| 376 | 394 | $this->update(array('counter_views' => ++$counter), $listing_id); |
| 395 | + } | |
| 396 | + | |
| 397 | + public function update_listings_views($listing_ids = [], $increment = 1) | |
| 398 | + { | |
| 399 | + if(empty($listing_ids) ) | |
| 400 | + return false; | |
| 401 | + | |
| 402 | + $sql = 'UPDATE '.$this->_table_name.' SET `counter_results_views` = `counter_results_views`+'.$increment.' WHERE post_id IN ('.join(',', $listing_ids).')'; | |
| 403 | + $this->db->query($sql); | |
| 377 | 404 | } |
| 378 | 405 | |
| 379 | 406 | } |
| 380 | 407 | ?> |