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
View bundler.js
const Bundler = require('parcel-bundler');
const Path = require('path');
const file = Path.join(__dirname, './src/main.js');
const options = {
outDir: Path.join(__dirname, './dist'),
outFile: 'bundle.min.js',
watch: true,
cache: false,
@jchristopher
jchristopher / functions.php
Created Sep 5, 2019
Tell SearchWP to persist Extra Metadata
View functions.php
<?php
add_filter( 'searchwp_persist_extra_metadata', '__return_true' );
@jchristopher
jchristopher / functions.php
Created Sep 4, 2019
Tell SearchWP to index term names from ACF (Advanced Custom Fields) Taxonomy fields
View functions.php
<?php
// Tell SearchWP to index term names from ACF (Advanced Custom Fields) Taxonomy fields.
add_filter( 'searchwp_custom_fields', function( $meta_value, $meta_key, $the_post ) {
$acf_taxonomy_field_names = array( 'mytaxfield1', 'mytaxfield2' );
if ( ! in_array( $meta_key, $acf_taxonomy_field_names ) ) {
return $meta_value;
}
View spinner.css
@keyframes searchwp-spinner-line-fade-quick {
0%, 39%, 100% {
opacity: 0.25;
}
40% {
opacity: 1;
}
}
View phpunit.sh
wp-content/plugins/myplugin$ phpunit
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 7.5.15 by Sebastian Bergmann and contributors.
...R%
wp-content/plugins/myplugin$
View functions.php
<?php
// this snippet is based on SearchWP's sample Supplemental Search Engine results template found here:
// https://searchwp.com/docs/configuration/#supplemental
// **************************** NOTE ****************************
// this snippet is just a portion of your search results template
// **************************** NOTE ****************************
View style.css
.searchwp-revised-search-notice {
margin: 0 calc(10% + 60px) 1em;
padding: 0.6em;
background: #f7f7f7;
border: 1px solid #e7e7e7;
border-radius: 2px;
}
.searchwp-suggested-revision-query {
font-style: italic;
@jchristopher
jchristopher / functions.php
Created Aug 14, 2019
Customize the keywords used by SearchWP Related
View functions.php
<?php
add_filter( 'searchwp_related_keywords', function( $terms, $post_id ) {
// $terms is what's currently stored as the keywords.
// TODO: Customize $terms to be the string of terms you _want_ to use.
return $terms;
}, 21, 3 );
@jchristopher
jchristopher / functions.php
Created Aug 7, 2019
Remove periods from search query in SearchWP
View functions.php
<?php
// Remove periods from search query in SearchWP.
add_filter( 'searchwp_terms', function( $query, $engine ) {
return str_replace( '.', '', $query );
}, 10, 2 );
@jchristopher
jchristopher / functions.php
Created Jul 30, 2019
Adjust SearchWP calculated weight based on post publish date
View functions.php
<?php
// Adjust calculated weight to consider how recently the entry was published.
add_filter( 'searchwp_weight_mods', function( $sql ) {
global $wpdb;
// Depending on the resulting calculation, you can modify how much the date influences the total weight.
$modifier = 1;
$sql .= " + ( ( UNIX_TIMESTAMP( NOW() ) - ( UNIX_TIMESTAMP( NOW() ) - UNIX_TIMESTAMP( {$wpdb->posts}.post_date ) ) - (SELECT UNIX_TIMESTAMP( post_date ) FROM {$wpdb->posts} WHERE post_status = 'publish' ORDER BY post_date ASC LIMIT 1 ) ) / 86400 ) * {$modifier}";
You can’t perform that action at this time.