Skip to content

Instantly share code, notes, and snippets.

@jchristopher
jchristopher / retry-failed.php
Created July 6, 2023 10:08 — forked from ryanshoover/retry-failed.php
Action Scheduler retry failed jobs
<?php
// Instance of the batch processing job.
$job = MyBatchJob();
// How many failed attempts do you want to process.
$batch_max_attempts = 3;
add_action( 'action_scheduler_failed_execution', 'maybe_retry_failed_batch' );
add_action( 'action_scheduler_failed_action', 'maybe_retry_failed_batch' );
@jchristopher
jchristopher / functions.php
Last active April 4, 2023 12:27
Use Elementor to power SearchWP Supplemental Engine
<?php
// @link https://searchwp.com/v3/docs/kb/using-elementor-for-supplemental-engines/
// We need to flag the search form.
add_action( 'elementor_pro/search_form/after_input', function( $form ) {
// Check to see if this is the right Search Form.
$settings = $form->get_data( 'settings' );
@jchristopher
jchristopher / searchwp-customizations.php
Created May 30, 2021 03:14
Tell SearchWP to exclude password protected results
<?php
// Tell SearchWP to exclude password protected results.
add_filter( 'searchwp\query\mods', function( $mods ) {
global $wpdb;
$mod = new \SearchWP\Mod();
$mod->set_local_table( $wpdb->posts );
$mod->on( 'ID', [ 'column' => 'id' ] );
$mod->raw_where_sql( function( $runtime ) {
@jchristopher
jchristopher / search-results.php
Last active December 11, 2022 07:43
SearchWP Live Ajax Search results template to output a custom Source (Users in this case) https://searchwp.com/documentation/knowledge-base/custom-source-results-live-search/
<?php
// Execute a search using our supplemental SearchWP Engine.
$search_query = isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : null;
$search_results = [];
if ( ! empty( $search_query ) && class_exists( '\\SearchWP\\Query' ) ) {
$searchwp_query = new \SearchWP\Query( $search_query, [
'engine' => 'supplemental', // The Engine name.
'fields' => 'all', // Load proper native objects of each result.
] );
@jchristopher
jchristopher / functions.php
Last active December 11, 2022 07:36
Override SearchWP's "Did you mean?" output
<?php
// Override SearchWP's "Did you mean?" output.
class MySearchwpDidYouMean {
private $args;
function __construct() {
// Prevent SearchWP's automatic "Did you mean?" output.
add_filter( 'searchwp_auto_output_revised_search_query', '__return_false' );
@jchristopher
jchristopher / searchwp-customizations.php
Last active December 11, 2022 07:35
Prepend a dropdown in SearchWP Shortcode search forms with Supplemental Engines
<?php
/*
Plugin Name: SearchWP Customizations
Plugin URI:
Description:
Version:
Author: Jonathan Christopher
Author URI:
License:
License URI:
@jchristopher
jchristopher / searchwp-customizations.php
Created October 7, 2020 13:22
Customize SearchWP stopwords per Engine
<?php
/**
* Customize SearchWP stopwords per Engine.
*/
// Optional: remove all Stopwords so you can add only unique Stopwords per Engine.
add_filter( 'searchwp\stopwords', '__return_empty_array' );
// Add unique stopword(s) for a single SearchWP Engine.
@jchristopher
jchristopher / searchwp-customizations.php
Created August 31, 2020 12:48
Force quoted search logic in SearchWP when applicable
<?php
// Force multiple word searches to use quoted search logic if quotes are not added.
// NOTE: Quoted search must be enabled (checkbox on the Advanced tab)
add_filter(
'searchwp\query\search_string',
function( $search_string, $query ) {
// If there are already quotes, bail out.
if ( false !== strpos( $search_string, '"' ) ) {
return $search_string;
@jchristopher
jchristopher / functions.php
Created May 14, 2020 23:36
Prevent JetSmartFilters from overriding SearchWP's results
<?php
// Prevents JetSmartFilters from overriding SearchWP's results.
// @link https://searchwp.com/v3/docs/kb/compatibility-with-jetsmartfilters-for-elementor/
add_action( 'init', function() {
add_filter( 'elementor/theme/posts_archive/query_posts/query_vars', function( $query ) {
if ( is_search() && is_main_query() ) {
remove_all_filters( 'elementor/theme/posts_archive/query_posts/query_vars' );
}
@jchristopher
jchristopher / searchwp-customizations.php
Created March 11, 2021 14:16
Integrate SearchWP with JetSmartFilters search using JetEngine Listing Grid to display results
<?php
// Integrate SearchWP with JetSmartFilters search using
// JetEngine Listing Grid to display results.
add_action( 'pre_get_posts', function( $wp_query ) {
if (
! isset( $wp_query->query['jet_smart_filters' ] )
|| empty( $wp_query->query['s'] )
) {
return;