1 year ago
<?php
/**
* removes all sources that are custom fields with "_" named meta_key
* from data sources in Facet settings
* keys in sources include "custom_fields", "posts, "taxonomies"
* integrations add "upt" for user post type fields, "woocommerce", "acf"
* context is 'default' for facet settings, context would be 'builder' for layout builder items
**/
add_filter( 'facetwp_facet_sources', function( $sources, $context ) {
foreach ( $sources AS $key => $value ) {
if ( "custom_fields" == $key && 'default' == $context ) {
$choices = array_values( array_filter( $value['choices'], function( $value, $key ) {
if ( str_starts_with( $key, "cf/_" ) ) {
return false;
}
return true;
}, ARRAY_FILTER_USE_BOTH ) );
$sources[$key]['choices'] = $choices;
}
}
return $sources;
}, 10, 2 );
1 year ago
<?php
// Add the new data source
add_filter( 'facetwp_facet_sources', function( $sources ) {
$sources['woocommerce']['choices']['woo/price_incl_tax'] = __( 'Price (incl. tax)' );
return $sources;
}, 20 );
// Handle the new data source
add_filter( 'facetwp_indexer_post_facet', function( $return, $params ) {
$facet = $params['facet'];
$defaults = $params['defaults'];
$post_id = (int) $defaults['post_id'];
if ( 'product' == get_post_type( $post_id ) && 'woo/price_incl_tax' == $defaults['facet_source'] ) {
$product = wc_get_product( $post_id );
$price = wc_get_price_including_tax( $product );
$defaults['facet_value'] = $price;
$defaults['facet_display_value'] = $price;
FWP()->indexer->index_row( $defaults );
return true;
}
return $return;
}, 10, 2 );
3 years ago
<?php
add_filter( 'facetwp_facet_sources', function( $sources ) {
foreach ( $sources['custom_fields']['choices'] as $key => $value ) {
if ( 0 === strpos( $value, '_stcr' ) ) {
unset( $sources['custom_fields']['choices'][ $key ] );
}
}
return $sources;
});
6 years ago
<?php
/** inherit adds attachment indexing **/
add_filter( 'facetwp_indexer_query_args', function( $args ) {
$args['post_status'] = array( 'publish', 'inherit' );
return $args;
});
/** post_mime_type is the column in the posts table to add **/
add_filter( 'facetwp_facet_sources', function( $sources ) {
$sources['posts']['choices']['post_mime_type'] = 'Media Type';
return $sources;
});
/** modifies string for mine type
** example image/png becomes image
**/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'post_mime_type' == $params['facet_source'] ) {
$value = $params['facet_display_value'];
$value = substr( $value, 0, strpos( $value, '/' ) );
$params['facet_value'] = $params['facet_display_value'] = $value;
}
return $params;
}, 10, 2 );