请温柔点,我对所有这些编码都是新手!我终于找到了如何获得前端下拉字段,允许我从EDD类别中进行选择(我从Codex中获得):
<div class="gallery-row">
<li id="categories">
<h2><?php _e( \'Categories:\' ); ?></h2>
<form id="category-select" class="category-select" action="<?php echo esc_url( home_url( \'/\' ) ); ?>" method="get">
<?php $args = array(
\'taxonomy\' => \'download_category\', // EDD custom post type Taxonomy
\'order\' => \'ASC\' // Order of the list
);
wp_dropdown_categories($args); ?>
<input type="submit" name="submit" value="view" />
</form>
</li>
</div>
这是我的原始代码,\'selecttaxonomy\'是ACF分类字段(仅显示在后端):
<div class="content clearfix"><div class="gallery-row2">
<?php
$current_page = get_query_var(\'paged\'); // Retrieving the data
$per_page = get_option(\'posts_per_page\');
$offset = $current_page > 0 ? $per_page * ($current_page -1) : 0;
$taxval = get_field(\'selecttaxonmy\');
$product_args = array(
\'post_type\' => \'download\',
\'posts_per_page\' => $per_page,
\'offset\' => $offset,
\'download_category\' => $taxval,
);
$products = new WP_Query($product_args);
?>
<?php if ($products->have_posts()) : $i = 1; ?> //and off into the loop.....
我搞不清楚的是如何用下拉列表的输出替换“selecttaxonomy”-请提供帮助。我正在处理的页面是:
https://ageingdj.com/0anotheredd-test/ (请忽略样式)
SO网友:Nathan Johnson
wp_dropdown_categories()
将生成一个默认名称和id为的select元素cat
. 可以通过为传递不同的值来更改这些值id
和cat
在$args
大堆默认值value
它使用的是术语\\u id。这取决于您在get_field()
函数,您也可以在$args
大堆
$args = array(
\'taxonomy\' => \'download_category\',
\'order\' => \'ASC\',
\'value_field\' => \'slug\',
);
然后在第二部分:
$cat = esc_attr( $_GET[ \'cat\' ] );
$product_args = array(
\'post_type\' => \'download\',
\'posts_per_page\' => $per_page,
\'offset\' => $offset,
\'download_category\' => $cat,
);
我从未以这种方式将ACF和EDD结合起来,因此可能需要一些修改。