Home › Forums › Front-end Issues › posts_clauses drop ACF get_field function › Reply To: posts_clauses drop ACF get_field function
Its work for me
add_filter('posts_clauses', 'sem_order_by_stock_status');
function sem_order_by_stock_status($posts_clauses) {
global $wpdb;
// only change query on WooCommerce loops when ACF fields are not requested in the WHERE statement
if (!is_acf_request($posts_clauses['where']) && is_woocommerce() && (is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy())) {
$posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
$posts_clauses['orderby'] = " istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
$posts_clauses['where'] = " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
}
return $posts_clauses;
}
function is_acf_request($text){
if (strpos($text, 'acf-field'))
return true;
return false;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.