我已经花了几天的时间来研究这个问题,但我仍然没有弄明白。我正在尝试制作高级搜索过滤器,根据两个条件对特定类别的帖子进行排序:位置(自定义字段)和发布日期(默认WordPress日期)。我希望用户能够按位置对帖子进行排序,并在按下搜索按钮之前指定帖子顺序(降序或升序)。到目前为止,我设法对位置进行了搜索,但我不知道如何将这两个标准结合起来,也不知道如何按日期对帖子进行排序:
<form name="search" action="" method="get">
<select name="place">
<?php
$metakey = \'place\';
$places = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
if ($places) {
foreach ($places as $place) {
echo "<option value=\\"" . $place . "\\">" . $place . "</option>";
}
}
?>
</select>
<select class="dropdown-class" name="sort-posts" id="sortbox">
<option disabled>Sort by</option>
<option value="&orderby=date&order=dsc">Newest</option>
<option value="&orderby=date&order=asc">Oldest</option>
</select>
<input type="submit" value="Search" />
</form>
<?php
$places = $_GET[\'place\'];
if ($places) {
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args=array(
\'cat\'=>6,
\'meta_value\' => $places,
\'paged\'=>$paged,
);
query_posts($args);
} else {
query_posts(\'cat=6&posts_per_page=4\');
}
if ($places) { ?>
<h1>Search for: <?php echo $places; ?></h3>
<?php } else { ?>
<h3></h3>
<?php } ?>
<div class="content-area">
<?php if ( have_posts() ) : ?>
<header class="archive-header">
<?php
the_archive_title( \'<h1 class="archive-title">\', \'</h1>\' );
the_archive_description( \'<div class="archive-description">\', \'</div>\' );
?>
</header><!-- .page-header -->
<?php
while ( have_posts() ) :
the_post();
get_template_part( \'template-parts/content\', get_post_format() );
endwhile;
endif;
?>
</div><!-- .content-area -->
我不知道该怎么做。我在网上搜索了几个小时,但找不到任何解决办法。任何帮助都将不胜感激。