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 Jun 12, 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 / functions.php
Last active Jun 5, 2019
Better control SearchWP during WP All Import import routine https://searchwp.com/docs/kb/best-work-content-imports/
View functions.php
<?php
/**
* WP All Import SearchWP PRE-import routine
*
* @link https://searchwp.com/docs/kb/best-work-content-imports/
*/
function myswp_before_xml_import( $import_id ) {
// Pause the SearchWP indexer during import
SWP()->indexer_pause();
View functions.php
<?php
/**
* Index WooCommerce Product Variations
*/
// Add product variations to the list of post types to index
function my_searchwp_indexed_post_types( $post_types ) {
if ( ! in_array('product_variation', $post_types ) ) {
$post_types = array_merge( $post_types, array( 'product_variation' ) );
@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 -->
@jchristopher
jchristopher / gist:3d9fe252561efa9aa6c2
Last active May 14, 2019
The default configurations array for SearchWP Live Search
View gist:3d9fe252561efa9aa6c2
<?php
$configs = array(
'default' => array( // 'default' config
'engine' => 'default', // search engine to use (if SearchWP is available)
'input' => array(
'delay' => 500, // wait 500ms before triggering a search
'min_chars' => 3, // wait for at least 3 characters before triggering a search
),
'parent_el' => 'body', // selector of the parent element for the results container
View functions.php
<?php
add_filter( 'searchwp_do_settings_backup', '__return_false' );
@jchristopher
jchristopher / gist:a57ca0426be3ca9676e2
Last active May 7, 2019
Tell SearchWP to return results in a random order (as opposed to ordered by relevance)
View gist:a57ca0426be3ca9676e2
<?php
function my_searchwp_return_orderby_random( $random, $engine ) {
// if it's not the default search engine, have results be random
if ( 'default' !== $engine ) {
$random = true;
}
return $random;
@jchristopher
jchristopher / gist:7862503
Last active May 6, 2019
Modify the SearchWP search terms after all sanitization has taken place
View gist:7862503
<?php
function my_searchwp_pre_search_terms( $terms, $engine ) {
if ( 'myengine' == $engine ) {
// do something with the terms
}
return $terms;
}
@jchristopher
jchristopher / gist:3135783eb3521bebbc5e
Created May 5, 2014
Disable the default SearchWP Live Search results theme CSS while retaining the positioning
View gist:3135783eb3521bebbc5e
<?php
function my_remove_searchwp_live_search_theme_css() {
wp_dequeue_style( 'searchwp-live-search' );
}
add_action( 'wp_enqueue_scripts', 'my_remove_searchwp_live_search_theme_css' );
You can’t perform that action at this time.