Gists

by mgibbs189 - 3 years ago

<?php

// props @zaphod-42 <https://wordpress.org/support/topic/not-working-with-facetwp/#post-9168365>
add_filter( 'facetwp_pre_filtered_post_ids', function( $post_ids ) {
    if ( ! empty( $post_ids ) && is_object( $post_ids[0] ) ) {
        $post_ids = wp_list_pluck( $post_ids, 'ID' );
    }
    return $post_ids;
});

by mgibbs189 - 4 years ago

<?php

add_filter( 'facetwp_pre_filtered_post_ids', 'store_pre_filtered_post_ids' );
add_filter( 'facetwp_filtered_post_ids', 'store_filtered_post_ids' );

function store_pre_filtered_post_ids( $post_ids ) {
    $GLOBALS['unfiltered_ids'] = $post_ids;
    return $post_ids;
}

function store_filtered_post_ids( $post_ids ) {
    $GLOBALS['filtered_ids'] = $post_ids;

    if ( isset( $GLOBALS['unfiltered_ids'] ) ) {
        return $GLOBALS['unfiltered_ids'];
    }
    return $post_ids;
}


<?php $filtered_ids = isset( $GLOBALS['filtered_ids'] ) ? $GLOBALS['filtered_ids'] : array(); ?>

<?php while ( have_posts() ): the_post(); ?>
    <?php $classname = in_array( get_the_ID(), $filtered_ids ) ? '' : 'ghost'; ?>
    <p class="<?php echo $classname; ?>">
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </p>
<?php endwhile; ?>