Gists

by mgibbs189 - 7 months ago

<?php

/**
 * Add the new "Featured" Data Source within the WooCommerce heading
 */
add_filter( 'facetwp_facet_sources', function( $sources ) {
    $sources['woocommerce']['choices']['woo/featured'] = __( 'Featured' );
    return $sources;
}, 20 );


/**
 * Index the featured products
 * Note: set the facet type to "Checkboxes" and the data source to "Featured"
 * then save and re-index
 */
add_filter( 'facetwp_indexer_post_facet', function( $return, $params ) {
    $facet = $params['facet'];
    $defaults = $params['defaults'];
    $source = isset( $facet['source'] ) ? $facet['source'] : '';

    if ( 'woo/featured' == $source ) {
        $current_id = (int) $defaults['post_id'];
        $all_featured_ids = wc_get_featured_product_ids();
        if ( in_array( $current_id, $all_featured_ids ) ) {
            $defaults['facet_value'] = 1;
            $defaults['facet_display_value'] = __( 'Is Featured' );
            FWP()->indexer->index_row( $defaults );
        }
        $return = true;
    }

    return $return;
}, 10, 2 );
by mgibbs189 - 1 year ago

<?php

// Add the following to your (child) theme's functions.php

add_filter( 'facetwp_facet_sources', function( $sources ) {
    if ( class_exists( 'coauthors_plus') && isset( $sources['taxonomies']['choices']['tax/author'] ) ) {
        $sources['co_authors'] = array(
            'label' => __( 'Co-Authors', 'co-authors-plus-for-facetwp' ),
            'choices' => array(
                'tax/author' => __( 'Authors', 'co-authors-plus-for-facetwp' ),
            )
        );
        unset( $sources['taxonomies']['choices']['tax/author'] ); // remove the duplicate
    }
    return $sources;
}, 10 );
by djrmom - 1 year 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 );
by djrmom - 2 years ago

<?php

/**
 * add additional source to select as Taxonomy Types
 */
add_filter( 'facetwp_facet_sources', function( $sources ) {

	$sources['posts']['choices']['tax_type'] = 'Taxonomy Types';
	return $sources;

}, 10);

/**
 * Create custom row indexer
 */
add_filter( 'facetwp_indexer_row_data', function( $rows, $args ) {

    if ( 'tax_type' == $args['defaults']['facet_source'] ) {

        $taxes = get_post_taxonomies( $args['defaults']['post_id'] );

        if ( empty( $taxes ) ) {
            return false;
        }

	    $output = array();

	    foreach ( $taxes as $tax ) {

		    $terms = wp_get_post_terms( $args['defaults']['post_id'], $tax );

		    if ( is_wp_error( $terms ) || empty( $terms ) ) {
		        continue;
            }

            $tax_type = get_taxonomy( $tax );

		    if ( ! $tax_type->public ) {
		        continue;
            }

		    $params = $args['defaults'];
		    $params['facet_value'] = $tax;
		    $params['facet_display_value'] = esc_html( $tax_type->label );
		    $output[] = $params;
        }

        return $output;
    }

	return $rows;

}, 10, 2 );
by mgibbs189 - 2 years ago

<?php

// Add to your (child) theme's functions.php
add_filter( 'facetwp_facet_sources', function( $sources ) {
    if ( class_exists( 'coauthors_plus') && isset( $sources['taxonomies']['choices']['tax/author'] ) ) {
        $sources['co_authors'] = array(
            'label' => 'Co-Authors',
            'choices' => array(
                'tax/author' => 'Authors'
            )
        );
    }
    return $sources;
}, 10 );