Gists

2 years ago
<?php

// Add to your (child) theme's functions.php
// Replace "my_range" with your actual facet name

add_filter( 'facetwp_indexer_row_data', function( $rows, $params ) {
    if ( 'my_range' == $params['facet']['name'] && empty( $rows ) ) {
        $new_row = $params['defaults'];
        $new_row['facet_value'] = 0;
        $new_row['facet_display_value'] = 0;
        $rows[] = $new_row;
    }
    return $rows;
}, 10, 2 );
1 year ago
<?php

add_filter( 'facetwp_indexer_row_data', function( $rows, $params ) {
    if ( 'keyword' == $params['facet']['name'] ) {
        $new_row = $params['defaults'];
        $post_id = (int) $new_row['post_id'];
        $new_row['facet_value'] = $post_id;
        $new_row['facet_display_value'] = get_the_title( $post_id );
        $rows[] = $new_row;
    }
    return $rows;
}, 10, 2 );
7 years ago
<?php
/** adds a "View All" index value to every post
 ** change 'my_radio' to the name of the radio facet to apply to
 ** 'View All' can be changed to whatever label is preferred
 ** reindex after add this code
 **/

add_filter( 'facetwp_indexer_row_data', function( $rows, $params ) {
  if ( 'my_radio' == $params['facet']['name'] ) {
    $new_row = $params['defaults'];
    $new_row['facet_value'] = 'all';
    $new_row['facet_display_value'] = 'View All';
    $rows[] = $new_row;
  }
  return $rows;
}, 10, 2 );