Post Publication Year Facet
Indexes des post publication year. Can be used with an „fSelect“ facet for a list of publication years.
add_filter( 'facetwp_index_row', 'bubdev_facetwp_index_post_year', 10, 2 );
/**
* FacetWP Index: Post Year Only
*/
function bubdev_facetwp_index_post_year( $params, $class ) {
if ( $params['facet_name'] == 'wpost_date' ) {
$raw_value = $params['facet_value'];
$params['facet_value'] = date( 'Y', strtotime( $raw_value ) );
$params['facet_display_value'] = $params['facet_value'];
}
return $params;
}
add_filter( 'facetwp_facet_orderby', 'bubdev_facetwp_orderby_post_year_desc', 10, 2 );
/**
* FacetWP Orderby: Date Descending
*/
function bubdev_facetwp_orderby_post_year_desc( $orderby, $facet ) {
if ( 'wpost_date' == $facet['name'] ) {
$orderby = 'f.facet_value+0 DESC';
}
return $orderby;
}
Add multiple values to autocomplete facet
Adds multiple values from a comma separated list to a shared autocomplete facet.
Hinweis: Komma-getrennte Schlagwortliste. Für eine ordentliche Indizierung (Filtermöglichkeit) dürfen nur Kommas, keine sonstigen Satzzeichen verwendet werden.
add_filter( 'facetwp_index_row', 'bubdev_facetwp_index_tags_from_string', 10, 2 );
function bubdev_facetwp_index_tags_from_string( $params, $class ) {
// Merge cpt-Event tags facet into cpt-Party title facet.
if ( 'event_tags' == $params['facet_name'] ) {
// Merge post title facet into party facet.
$params['facet_name'] = 'event_party';
// Account for event tours.
$tour_id = bubdev_event_tour_id( $params['post_id'] );
$proper_post_id = $tour_id ?: $params['post_id'];
// Add event tags one by one from single string.
$tags_list = bubdev_field( 'bub_event_tags', $proper_post_id );
$tags_arr = explode( ',', $tags_list );
foreach ( $tags_arr as $tag ) {
$tag = trim( $tag );
$params['facet_value'] = $tag;
$params['facet_display_value'] = $tag;
$class->insert( $params );
}
// Skip the default indexing query.
return false;
}
// Return params.
return $params;
}