Skip to content

Instantly share code, notes, and snippets.

Jon Christopher jchristopher

Block or report user

Report or block jchristopher

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jchristopher
jchristopher / functions.php
Last active Jul 10, 2019
Tell FacetWP to skip SearchWP when an empty s query parameter is passed
View functions.php
<?php
// Tell FacetWP to disregard SearchWP if the search query is empty.
add_filter( 'facetwp_facets', function( $facets ) {
if ( ! isset( $_REQUEST['s'] ) || ! empty( $_REQUEST['s'] ) || empty( $facets ) || ! is_array( $facets ) ) {
return $facets;
}
foreach ( $facets as $key => $facet ) {
if ( 'search' !== $facet['type'] ) {
@jchristopher
jchristopher / functions.php
Created Jul 9, 2019
Prevent WP-Views from overriding SearchWP's results
View functions.php
<?php
// Prevent WP-Views from overriding SearchWP's results.
add_filter( 'wpv_filter_wpv_override_wordpress_archive', function( $wpa_to_apply, $wpa_slug ) {
if ( 'view_search-page' !== $wpa_slug ) {
return $wpa_to_apply;
}
return false;
}, 999, 2 );
@jchristopher
jchristopher / functions.php
Created Jul 8, 2019
Integrate SearchWP with SEO Framework local search exclusion
View functions.php
<?php
function my_searchwp_seo_framework_integration( $ids ) {
$post_ids = get_posts( array(
'post_type' => 'any',
'fields' => 'ids',
'nopaing' => true,
'meta_query' => array(
array(
'key' => 'exclude_local_search',
@jchristopher
jchristopher / functions.php
Created Jun 26, 2019
Customize the directory used in SearchWP Modal Form's template loader
View functions.php
<?php
add_filter( 'searchwp_modal_form_template_dir', function( $dir ) {
return 'my-searchwp-modal-forms';
} );
View tmp.sh
# Build development version of SearchWP Modal Search Form bundle
npm run dev
# Build production version of SearchWP Modal Search Form bundle
npm run build
# Build development version of SearchWP Modal Search Form block
npm run blockdev
# Build production version of SearchWP Modal Search Form block
View functions.php
<?php
searchwp_modal_form_trigger( array(
'echo' => true, // Whether to echo
'type' => 'button', // Either 'link' or 'button'
'text' => 'Open Search', // Text of the trigger
'engine' => 'my_searchwp_engine', // SearchWP engine (when applicable)
'template' => 'My Custom Template', // Modal template to use (see docs)
) );
@jchristopher
jchristopher / functions.php
Created Jun 26, 2019
Display the default SearchWP Modal Form trigger
View functions.php
<?php
searchwp_modal_form_trigger();
@jchristopher
jchristopher / functions.php
Last active Jun 19, 2019
Tell SearchWP to incercept ACF Relationship Field searches
View functions.php
<?php
// Callback to have SearchWP intercept ACF Relationship field searches.
function my_searchwp_acf_relationship_field_search( $args, $field, $post_id ) {
if ( empty( $args['s'] ) || ! class_exists( 'SWP_Query' ) ) {
return $args;
}
// Assume that the SearchWP engine to use is the defined admin search engine
// from SearchWP's Advanced settings screen.
@jchristopher
jchristopher / gutenberg.html
Last active May 14, 2019
Sample of reusable block in Gutenberg
View gutenberg.html
<!-- wp:paragraph -->
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus
tincidunt nunc vel consequat dapibus. Pellentesque aliquet felis
nulla, sit amet efficitur mauris finibus in. </p>
<!-- /wp:paragraph -->
<!-- wp:block {"ref":50} /-->
<!-- wp:heading -->
<h2>Lipsum dolor sit</h2>
@jchristopher
jchristopher / gutenberg.html
Last active May 14, 2019
Sample of Gutenberg content in the database
View gutenberg.html
<!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tincidunt nunc vel
consequat dapibus. Pellentesque aliquet felis nulla, sit amet efficitur mauris
finibus in. </p>
<!-- /wp:paragraph -->
<!-- wp:heading -->
<h2>Lipsum dolor sit</h2>
<!-- /wp:heading -->
You can’t perform that action at this time.