I created Custom Post Type in WordPress to record certain data like product id of woocommerce and some personal user entered information in frontend, and those information are properly listed in wp list table, now i am trying to sort by product name, but i have only product id,(in list table i fetch product name using woocommerce native function), sort by product id was working properly using the below code
add_filter('parse_query', array($this, 'parse_query'));
public function parse_query($query) {
global $pagenow;
if (!is_admin())
return;
$orderby = $query->get('orderby');
if (isset($_GET['post_type'])) {
$type = $_GET['post_type'];
//frontendtestwp is a custom cpt of wordpress
if ('frontendtestwp' == $type && is_admin() && $pagenow == 'edit.php') {
// for orderby just order based on product id
$query->set('meta_key', 'frontend_pid'); //contain product id
$query->set('orderby', 'meta_value_num');
}
}
}
Now if i want to sort based on product name i have two option one is to record the product name in my side additionally(which i don't want to do, if any update to the original product name then that sorting result will be based on old data).
Second option is using posts_where filter(currently trying this option) as my idea is to check custom post type of product(woocommerce) additionally with product_id = my meta value and order by product title
in posts_where
filter i added the below code to check in product as well but i am stuck in condition check with (id of product==my_meta_value_product_id)
$where .= " AND `post_type`='product'";
Initially i thought to use Inner join but it is not needed because all custom post types are in one table, only thing i want to check is order by title of product based on my meta product id.
Is there any way to achieve my desired result with my existing data(product id)?