我已经实现了代码,但排序是按字母顺序进行的。虽然我想按产品进入日期排序:
function my_shop_custom_products_query( $q ) {
$q->get( \'meta_key\', \'_thumbnail_id\' );
$q->set(\'orderby\', \'meta_value\');
$q->set(\'order\', \'DESC\');
$q->set( \'meta_query\', array( \'relation\' => \'OR\', array(
\'orderby\' => \'meta_value\',
\'order\' => \'DESC\',
\'key\' => \'_thumbnail_id\',
\'compare\' => \'NOT EXISTS\',
// \'value\' => \'0\'
),
array(
\'key\' => \'_thumbnail_id\',
\'compare\' => \'>=\',
\'value\' => \'0\',
\'orderby\' => \'meta_value\',
\'order\' => \'DESC\'
)),
);
}
add_action( \'woocommerce_product_query\', \'my_shop_custom_products_query\' );