Last active
June 22, 2019 06:53
-
-
Save eto4detak/6903966591476de9ed7ba31fde53ded3 to your computer and use it in GitHub Desktop.
woo sql php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//получить Id заказов бронирования авто | |
public static function get_orders_ids($order_status = array('wc-completed', 'wc-on-hold')){ | |
global $wpdb; | |
$product_id = self::$settings['woo_id_product']; | |
$results = $wpdb->get_col(" | |
SELECT order_items.order_id | |
FROM {$wpdb->prefix}woocommerce_order_items as order_items | |
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id | |
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID | |
WHERE posts.post_type = 'shop_order' | |
AND posts.post_status IN ('" . implode("','", $order_status) . "') | |
AND order_items.order_item_type = 'line_item' | |
AND order_item_meta.meta_key = '_product_id' | |
AND order_item_meta.meta_value = '$product_id' | |
"); | |
return $results; | |
} | |
/*======================================================== | |
* sql limit | |
========================================================*/ | |
global $wpdb; | |
$limit = 5000; | |
$i = 1; | |
$user_posts = []; | |
$return = $wpdb->get_results( $wpdb->prepare( | |
"SELECT `ID`, `post_title` FROM $wpdb->posts WHERE post_status = 'publish' limit ". $limit*($i -1).','.$limit*$i, '%'. $wpdb->esc_like( $title ) .'%') ); | |
$user_posts = array_merge($user_posts, $return); | |
if (!empty($return)) { | |
while ( !empty($return)) { | |
$i++; | |
$return = $wpdb->get_results( $wpdb->prepare( | |
"SELECT `ID`, `post_title` FROM $wpdb->posts WHERE post_status = 'publish' limit ". $limit*($i -1).','.$limit*$i, '%'. $wpdb->esc_like( $title ) .'%') ); | |
$user_posts = array_merge($user_posts, $return); | |
} | |
} | |
// проверить существует ли такое название поста | |
function marafon_exist_post_title($title) | |
{ | |
global $wpdb; | |
$myposts = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_status = 'publish' AND post_title LIKE '%s' limit 1", '%'. $wpdb->esc_like( $title ) .'%') ); | |
return $myposts; | |
} | |
/*======================================================== | |
* big data | |
========================================================*/ | |
function marafon_get_users_post_all($title = '') | |
{ | |
global $wpdb; | |
$limit = 5000; | |
$i = 1; | |
$user_posts = []; | |
$return = $wpdb->get_results( $wpdb->prepare( "SELECT `ID`, `post_title` FROM $wpdb->posts WHERE post_status = 'publish' limit ". $limit*($i -1).','.$limit*$i, '%'. $wpdb->esc_like( $title ) .'%') ); | |
$user_posts = array_merge($user_posts, $return); | |
if (!empty($return)) { | |
while ( !empty($return)) { | |
$i++; | |
$return = $wpdb->get_results( $wpdb->prepare( | |
"SELECT `ID`, `post_title` FROM $wpdb->posts WHERE post_status = 'publish' limit ". $limit*($i -1).','.$limit*$i, '%'. $wpdb->esc_like( $title ) .'%') ); | |
$user_posts = array_merge($user_posts, $return); | |
} | |
} | |
echo '<pre class="aaa" style="display:">'; | |
var_dump('user_posts'); | |
// var_dump($user_posts); | |
echo '</pre>'; | |
return $user_posts; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment