【问题标题】:FacetWP filter from custom field checkbox来自自定义字段复选框的 FacetWP 过滤器
【发布时间】:2021-01-11 08:14:12
【问题描述】:

我有一个名为organic 的产品自定义字段,其值为yes/no。我想在我们的过滤器中显示一个复选框,上面写着“有机”。并且当检查在 db 中搜索 yes 值时。 FacetWP 中复选框的默认设置显示来自 db 的值。

如何在 FacetWP 中进行设置?

【问题讨论】:

    标签: wordpress facetwp


    【解决方案1】:

    这是您执行此任务的代码,不要忘记在每次更改名称后重新索引。

    /**
     * reindex after adding or updating this filter
     */
    add_filter( 'facetwp_index_row', function( $params, $class ) {
        if ( 'new_facet' == $params['facet_name'] ) { // change my_facet to your facet's name/slug
            if ( '1' == $params['facet_value'] ) { // be careful with 1 and 0 as values - https://www.php.net/manual/en/types.comparisons.php
                $params['facet_display_value'] = 'Organic'; // text to display in the facet choices
                }
            if ( '0' == $params['facet_value'] ) {
                $params['facet_display_value'] = 'McDonalds';
                }
        }
        return $params;
    }, 10, 2 );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-13
      • 1970-01-01
      • 2018-09-08
      • 2016-03-03
      • 1970-01-01
      • 2017-11-13
      • 2017-03-05
      • 1970-01-01
      相关资源
      最近更新 更多