WordPress Query: Combining 'in_stock' and 'sortby' Conditions
"Yes, you are correct. In order to make both 'in_stock' and 'sortby' conditions work together, you need to use the 'relation' parameter in the 'meta_query' array. \n\nCurrently, you have only included the 'meta_query' for 'in_stock' condition. To include the 'sortby' condition as well, you need to modify your code as follows:\n\nphp\n$data['meta_query'] = array(\n 'relation' => 'AND',\n array(\n 'key' => 'qqp_qty',\n 'value' => array('0'),\n 'compare' => '>'\n ),\n array(\n 'relation' => 'OR',\n array(\n 'key' => 'qqpd_price',\n 'value' => array(''),\n 'compare' => 'NOT IN'\n ),\n array(\n 'key' => 'qq_product_rate',\n 'value' => array(''),\n 'compare' => 'NOT IN'\n ),\n array(\n 'key' => 'qq_total_views',\n 'value' => array(''),\n 'compare' => 'NOT IN'\n )\n )\n);\n\n\nThis code adds the 'relation' parameter in the 'meta_query' array and includes all the conditions under it using the 'AND' and 'OR' relations. This way, both 'in_stock' and 'sortby' conditions will be applied together.\n
原文地址: https://www.cveoy.top/t/topic/qd9a 著作权归作者所有。请勿转载和采集!