我有一个名为“属性”的自定义帖子类型,并设置了一个归档页面来显示该类别内的帖子。
本质上,归档页面需要包含3种不同的查询类型;第一个用于显示CPT内帖子的搜索结果,第二个用于使结果可排序(通过询问自定义字段元值的下拉菜单查询),第三个用于显示CPT内的所有帖子。
虽然我不知道如何构造查询和循环-所有查询都是单独工作的,但我正在努力设置If/Else语句,使其在一个归档页面中工作,因此如果您有任何建议,我将不胜感激!
Query 1: Search Results
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'post_type\' => \'properties\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'property_size\',
\'value\' => $_GET[\'size\'],
\'compare\' => \'>=\'
),
array(
\'key\' => \'property_rent\',
\'value\' => $_GET[\'budget-from\'],
\'compare\' => \'>=\',
\'type\' => \'NUMERIC\'
),
array(
\'key\' => \'property_rent\',
\'value\' => $_GET[\'budget-to\'],
\'compare\' => \'<=\',
\'type\' => \'NUMERIC\'
)
),
\'paged\' => $paged
);
$query = new WP_Query( $args );
Query 2: Sortable Posts within CPT
if($_POST[\'square-sort-select\'] == 0):
$select = $_POST[\'square-sort-select\'];
$query = new WP_Query(array(
\'post_type\'=> \'properties\',
\'post_status\' => \'publish\',
\'meta_key\' => \'property_rent\',
\'orderby\' => \'property_rent\',
\'order\' => DESC
));
; elseif($_POST[\'square-sort-select\'] == 1):
$select = $_POST[\'square-sort-select\'];
$query = new WP_Query(array(
\'post_type\'=> \'properties\',
\'post_status\' => \'publish\',
\'meta_key\' => \'property_rent\',
\'orderby\' => \'property_rent\',
\'order\' => ASC
));
; elseif($_POST[\'square-sort-select\'] == 2):
$select = $_POST[\'square-sort-select\'];
$query = new WP_Query(array(
\'post_type\'=> \'properties\',
\'post_status\' => \'publish\',
\'order\' => DESC
));
Query 3: All Posts within CPT $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$query = new WP_Query();
$query->query(\'post_type=properties&posts_per_page=6&paged=\'.$paged);