2017-01-31 4 views
-1

私は、woocommerce管理画面でデフォルトのソート順を変更しようとしています。wocommerceダッシュボード画面でのデフォルトのソート順の変更

私は、デフォルトで製品ページごとに製品ページを並べ替えるために次のコードを試しています。

/* Sort posts in wp_list_table by column in ascending or descending order. */ 
function custom_post_order($query){ 
    /* 
     Set post types. 
     _builtin => true returns WordPress default post types. 
     _builtin => false returns custom registered post types. 
    */ 
    $post_types = get_post_types(array('_builtin' => false), 'names'); 
    /* The current post type. */ 
    $post_type = $query->get('post_type'); 
    /* Check post types. */ 
    if(in_array($post_type, $post_types) && $post_type == 'product'){ 
     /* Post Column: e.g. title */ 
     if($query->get('orderby') == ''){ 
      $query->set('orderby', 'title'); 
     } 
     /* Post Order: ASC/DESC */ 
     if($query->get('order') == ''){ 
      $query->set('order', 'ASC'); 
     } 
    } 
} 
if(is_admin()){ 
    add_action('pre_get_posts', 'custom_post_order'); 
} 

しかし、それは動作していないようです。誰かが私が間違っているところを指摘することができますかwoocommerceは製品列を別々に扱いますか?

ありがとうございます。

答えて

0

代わりにparse_queryをターゲットにします。これは私のために働いているようだ:中

/* Sort products in wp_list_table by column in ascending or descending order. */ 
function sp_41964737_custom_product_order($query){ 

    global $typenow; 

    if(is_admin() && $query->is_main_query() && $typenow == 'product'){ 

     /* Post Column: e.g. title */ 
     if($query->get('orderby') == ''){ 
      $query->set('orderby', 'title'); 
     } 
     /* Post Order: ASC/DESC */ 
     if($query->get('order') == ''){ 
      $query->set('order', 'ASC'); 
     } 

    } 
} 
add_action('parse_query', 'sp_41964737_custom_product_order'); 

結果:

screenshot of ordered products

+0

はありがとうございましたが、これは私のために働いていない – tousif

+0

他のプラグインを無効にしてみてくださいし、確認するために、デフォルトのテーマに切り替えてください。矛盾するものはない私は実際に結果が好きなので、私はテスト環境でそれを保つつもりです。 – helgatheviking

関連する問題