ワードプレスで絞り込み検索フォームを作っています。
検索結果の順序を古い順にしたいのですがどうすれば良いか分からず教えていただきたいです。
【フォーム部分】
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>"> <p class="search"> <label for="s" class="assistive-text"></label> <input class="search_con" type="text" name="s" id="s" placeholder="キーワード" /> </p> <?php $myposts = get_posts('cat=-1'); ?> <div class="pru1"> <div class="cp_ipselect cp_sl01"> <select name="catnum"> <option value="" selected>エリアで探す</option> <?php $categories = get_categories('orderby=slug'); foreach($categories as $category) : ?> <option value="<?php echo $category->term_id; ?>"><?php echo $category->cat_name; ?></option> <?php endforeach; ?> </select> </div> </div> <div class="pru2"> <div class="cp_ipselect cp_sl01"> <select name="post_tag"> <option value="" selected>得意分野から探す</option> <?php $taxonomy_name = 'post_tag'; $taxonomys = get_terms($taxonomy_name); if(!is_wp_error($taxonomys) && count($taxonomys)): foreach($taxonomys as $taxonomy): $tax_posts = get_tags(array('post_type' => get_post_type(), 'taxonomy' => $taxonomy_name, 'term' => $taxonomy->slug,) ); if($tax_posts): ?> <option value="<?php echo $taxonomy->slug; ?>"><?php echo $taxonomy->name; ?></option> <?php endif; endforeach; endif; ?> </select> </div> </div> <div class="submit"> <input class="button02" type="submit" value="検索" /> </div> <div style="clear: both"></div> </form> <div style="clear: both"></div> <?php endif;?>
【search.php】
<?php $s = $_GET['s']; $catnum = $_GET['catnum']; $post_tag = $_GET['post_tag']; //tax_query用 if($catnum){ $taxquerysp[] = array( 'taxonomy'=>'category', 'terms'=> $catnum, 'include_children'=>false, 'field'=>'term_id', 'operator'=>'AND' ); } if($post_tag){ $taxquerysp[] = array( 'taxonomy'=>'post_tag', 'terms'=> $post_tag, 'include_children'=>false, 'field'=>'slug', 'operator'=>'AND' ); } ?> <?php query_posts( array( 'tax_query' => $taxquerysp, 's' => $s, 'posts_per_page' => 5, // 表示件数 ) ); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
(質問文は編集できます)質問文のコードはそれぞれコードブロックで囲んでいただけませんか? ```(バッククオート3つ)で囲み、前後に改行をいれるか、コードを選択して「<code>」ボタンを押すとコードブロックになります。
回答2件
あなたの回答
tips
プレビュー