Skip to content

Instantly share code, notes, and snippets.

@djrmom
djrmom / custom-hooks.php
Created January 25, 2018 22:24
facetwp index date as raw value for sorting
<?php
add_filter( 'facetwp_index_row', function ( $params, $class ) {
if ( 'my_facet' == $params['facet_name'] ) { // change 'my_facet' to the name of your facet
$params['facet_value'] = get_the_date( 'Ymd', $params['post_id'] );
}
return $params;
}, 10, 2 );
@djrmom
djrmom / functions.php
Created January 26, 2018 14:37
limit post types on search page
<?php
/* limit types searched on wp search page */
add_action( 'pre_get_posts', function( $query ) {
if ( !is_admin() && $query->is_main_query() && $query->is_search() ) {
$query->set('post_type', 'post');
}
} );
@djrmom
djrmom / custom-hooks.php
Last active April 19, 2018 15:24
facetwp index lat/lng
<?php
function starkatcher_index_latlng( $params, $class ) {
if ( 'location' == $params['facet_name'] ) {
$latlong = explode(',', get_post_meta( $params['post_id'], 'sk-location', true ));
$lat = $latlong[0];
$long = $latlong[1];
// foreach ( (array) $params['facet_value'] as $post ) {
$params['facet_value'] = $lat;
@djrmom
djrmom / facetwp-map-facet.php
Created February 1, 2018 16:24
facetwp translations for map
<?php
add_action( 'plugins_loaded', 'facetmap_load_textdomain' );
/**
* Load plugin textdomain.
*/
function facetmap_load_textdomain() {
load_plugin_textdomain( 'fwp-map' );
}
@djrmom
djrmom / scripts.js
Created February 6, 2018 19:27
facetwp get value of facet filter
(function($) {
$(document).on('facetwp-loaded', function() {
if ('undefined' !== typeof FWP.facets['facet_name'] ) {
if ( $.inArray( 'some_value', FWP.facets['facet_name'] ) > -1 ) {
// update form value as needed in gravity form
}
}
});
})(jQuery);
@djrmom
djrmom / custom-hooks.php
Last active December 13, 2018 18:11
facetwp/loaded hook
<?php
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(function() {
FWP.hooks.addAction('facetwp/loaded', function() {
/* run code here after facetwp loaded, 100 below can be modified to set priority order */
}, 100 );
@djrmom
djrmom / custom-hooks.php
Created February 8, 2018 14:54
facetwp index a field in a related post type
<?php
/**
** look up and index a value from a post relationship field
** set the datasource to the relationship field
** get the post id of that related post and use it to
** lookup its associated value
** for ACF you may want get_field() instead of get_post_meta()
** remember to do a full re-index after adding code
** check the wp_facetwp_index table if needed to see what values are being indexed
**/
@djrmom
djrmom / display.php
Last active February 19, 2018 17:22
facetwp query pages
<?php while ( have_posts() ): the_post(); ?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<?php endwhile; ?>
@djrmom
djrmom / custom-hooks.php
Created February 20, 2018 00:09
facetwp conditional filter
<?php
add_filter( 'facetwp_use_search_relevancy', function( $value, $class ) {
if ( 'foo/bar' == $class->http_params['uri'] ) {
return false;
}
return $value;
}, 10, 2 );
@djrmom
djrmom / custom-hooks.php
Last active February 21, 2018 00:02
facetwp check category listing query for listify
<?php
// check for job_listings archive and don't use the query unless it is using menu_order
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( isset( $query->query_vars['post_type'] ) && 'job_listing' == $query->query_vars['post_type']
&& ( ! isset( $query->query_vars['taxonomy'] ) || '' == $query->query_vars['taxonomy'] ) ) {
if ( isset( $query->query_vars['order_by']['menu_order'] ) ) {
return true;
} else {
return false;
}