質問: \'wpsc_product_category\'";')); add_filter('posts_orderby', create_function('$a','global $wpdb; return "$wpdb->term_taxonomy.term_id desc";')); query_posts(''); お返事ありがとうございます!
回答: あなたはとても親しいです。私はしばらく前に同じ問題を抱えていました、そして それについてブログしました 。結合にもう1つ結合テーブルwp_termsがありません。このテーブルには、ソートしたい用語があります。これが私が使ったコードです:class orderwpscproducts { // flag for when a shop products post query is being created private $isproductquery = false; public function __construct() { // hooks for altering order of product pages add_filter('parse_query', array($this, 'filterproductquerymark'), 20); add_filter('posts_join', array($this, 'filterproductqueryjoins'), 20); add_filter('posts_orderby', array($this, 'filterproductqueryorderby'), 20); } /** * detect a posts query that should return a list of shop products, * and mark it for later filters * @param wp_query $query * @return wp_query */ public function filterproductquerymark($query) { $this->isproductquery = false; if (!is_admin() && (wpsc_is_in_category() || !empty($query->query_vars['wpsc_wine_style']))) { $this->isproductquery = true; } } /** * if the posts query is for a list of shop products, * then add some tables to the join so that we can sort by category name * @param string $joins * @return string */ public function filterproductqueryjoins($joins) { global $wpdb; if ($this->isproductquery) { $joins .= " inner join $wpdb->term_relationships wpsc_cat_rel on wp_posts.id = wpsc_cat_rel.object_id inner join $wpdb->term_taxonomy wpsc_cat_tax on wpsc_cat_tax.term_taxonomy_id = wpsc_cat_rel.term_taxonomy_id and wpsc_cat_tax.taxonomy = 'wpsc_product_category' inner join $wpdb->terms wpsc_cat on wpsc_cat.term_id = wpsc_cat_tax.term_id "; } return $joins; } /** * if the posts query is for a list of shop products, then sort by category name and product title * @param string $orderby * @return string */ public function filterproductqueryorderby($orderby) { if ($this->isproductquery) { $orderby = 'wpsc_cat.name asc, wp_posts.post_title asc'; } return $orderby; } } // create instance, will be kept alive by hooks new orderwpscproducts();