wordpressのキーワード検索結果を並び替えたいです。
welcartプラグインにて登録した商品をキーワード検索してヒットした商品をsearch.phpを介して一覧表示させています。
キーワード検索すると一覧が表示されるのですが、そこから価格の安い順で並び替えを行うと0件と出てしまいます。
ちなみにcategory.phpでも同じことをしているのですが、そちらだと価格の安い順に表示されます。
データベース内postmetaの_itemPriceMinに価格情報を入れています。
以下、試したコードになります。
search.php
<?php $srch = "\t" . '<input type="hidden" name="s" value="' . get_search_query() . '" />' . "\n"; ?> <form method="get" action="/"> <?php echo $srch; ?> <input type="hidden" name="sort" value="priceasc" /> <input type="submit" value="価格が安い順" /> </form> <?php if(have_posts()): while(have_posts()): the_post(); ?> 商品タイトル <?php endif; ?>
function.php
function add_sort_query_vars( $public_query_vars ) { $public_query_vars[] = 'meta_key'; $public_query_vars[] = 'meta_value'; return $public_query_vars; } add_filter( 'query_vars', 'add_sort_query_vars' ); function change_posts_per_page( $query ){ if( is_admin() || ! $query->is_main_query() ){ return; } if ( $query->is_search() ) { //価格の安い順 if( $_GET['sort'] == 'priceasc' ){ $query->set( 'meta_key', '_itemPriceMin' ); $query->set( 'orderby', array( 'meta_value_num' => 'ASC', 'date' => 'DESC' ) ); } } } add_action( 'pre_get_posts', 'change_posts_per_page' );
ご教示のほどよろしくお願いいたします。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/02 04:03
2018/04/02 08:22
2018/04/02 09:10
2018/04/02 09:44
2018/04/02 09:46
2018/04/03 02:39