Skip to content

Instantly share code, notes, and snippets.

@sc0ttkclark
Forked from waqashassan98/pods-help.php
Last active January 16, 2020 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sc0ttkclark/8fece91df8064663af54ae8f53a88f7b to your computer and use it in GitHub Desktop.
Save sc0ttkclark/8fece91df8064663af54ae8f53a88f7b to your computer and use it in GitHub Desktop.
<?php
//pods: https://imgur.com/a/MflzgtI
$search = sanitize_text_field( $search );
$query = array();
$query[] = 'brand.meta_value = ' . absint( $_REQUEST['brand_id'] );
$query[] = '
d.asset_name LIKE "%' . pods_sanitize_like( $search ) . '%"
OR product_d.sku like "%' . pods_sanitize_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(
// This will make sure it joins Product relationship data we need to know.
'select' => '`t`.*, `d`.*, `prod`.`ID`',
// Join the product data table so we can reference it.
'join' => 'LEFT JOIN `wp_pods_product` AS `product_d` ON `product_d`.`id` = `prod`.`ID`',
'limit' => 8,
'orderby' => 'date DESC',
'where' => '( ' . implode( ' ) AND ( ', $query) . ' )',
);
// 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