Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //od Roman Meidl
- add_shortcode( 'celkem-produktu', 'get_instock_products_count' );
- function get_instock_products_count(){
- global $wpdb;
- // The SQL query
- $result = $wpdb->get_col( "
- SELECT COUNT(p.ID)
- FROM {$wpdb->prefix}posts as p
- INNER JOIN {$wpdb->prefix}postmeta as pm ON p.ID = pm.post_id
- WHERE p.post_type LIKE '%product%'
- AND p.post_status LIKE 'publish'
- AND pm.meta_key LIKE '_stock_status'
- AND pm.meta_value LIKE 'instock'
- " );
- return reset($result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement