Last active
October 21, 2020 18:43
-
-
Save waqashassan98/db0903659c050e42c2c12d83bb5e2532 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* All items of a POD (CPT) | |
**/ | |
$params = array( | |
'limit' => -1, | |
); | |
$prods_pod = pods( 'im_products', $params ); | |
if( false != $prods_pod && $prods_pod->total_found()>0 ){ | |
while ( $prods_pod->fetch() ) { | |
$prod_id = $prods_pod->field('id'); | |
} | |
} | |
/** | |
* Simple Parmater Search | |
**/ | |
$params = array( | |
'limit' => -1, | |
'where' => "d.product_name like '".esc_sql(trim($level))."'", | |
); | |
$prods_pod = pods( 'im_products', $params ); | |
if( false != $prods_pod && $prods_pod->total_found()>0 ){ | |
while ( $prods_pod->fetch() ) { | |
$prod_id = $prods_pod->field('id'); | |
} | |
} | |
/** | |
* Relationship query | |
**/ | |
$params = array( | |
'limit' => -1, | |
'where' => "user_id.id = {$user_id} and product_id.id = {$id}", | |
); | |
$ua_pod = pods( 'user_access', $params ); | |
if( false != $ua_pod && $ua_pod->total_found()>0 ){ | |
while ( $ua_pod->fetch() ) {//should ideally run 1 time | |
$prod_id = $ua_pod->field('product_id'); | |
$url = get_post_meta($prod_id["ID"], "product_url", true); | |
} | |
} | |
/** | |
* Advanced Query | |
**/ | |
//pods: https://imgur.com/a/MflzgtI | |
$query = array(); | |
$query[] = "wp_postmeta.meta_key like 'brand' and wp_postmeta.meta_value = ".$_REQUEST['brand_id']; | |
$query[] = " d.asset_name LIKE \"%".$search."%\" or sku.sku like \"%".$search."%\" "; | |
//$query[] = " d.asset_name LIKE \"%".$search."%\" or sku.post_title like \"%".$search."%\" "; | |
//$query[] = " d.asset_name LIKE \"%".$search."%\" or sku.id like \"%".$search."%\" "; | |
$params = array( | |
'limit' => 8, | |
'orderby' => 'date DESC', | |
'where' => implode( " and ", $query), | |
'join' => "LEFT JOIN `wp_postmeta` ON `wp_postmeta`.`post_id` = `t`.`id` ", | |
// LEFT JOIN `wp_pods_product` ON `wp_pods_product`.`id` = sku.id | |
); | |
// Run the find | |
$mypod = pods( 'asset', $params ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment