Support

Account

Home Forums Front-end Issues posts_clauses drop ACF get_field function

Unread

posts_clauses drop ACF get_field function

  • Hello
    I try to use function for order by stock status in my store catalog but this code drop ACF get_field() function
    when function on, get_field return only ID of post (https://skr.sh/sGyfgZ3GwaP)
    and when function off, all right, get_field return array (https://skr.sh/sGyHPC9UUOw)
    please help me to find a reason

    add_filter( 'posts_clauses', 'order_by_stock_status', 2000 );
    function order_by_stock_status( $posts_clauses ) {
    global $wpdb;
    
    if ( 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;
    }
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.