Skip to content

Instantly share code, notes, and snippets.

<?php
// Disable 'Actions' Entry Panel Pane in OrganizeWP
// @link https://organizewp.com/docs/entry-panel/
add_filter( 'organizewp/entry_panel/panes/actions', '__return_false' );
@jchristopher
jchristopher / functions.php
Created August 4, 2022 15:49
Enable 'Modified' Info Column in OrganizeWP
<?php
// Enable 'Modified' Info Column in OrganizeWP
// @link https://organizewp.com/docs/entries/#information-columns
add_filter( 'organizewp/post_type/info_columns/modified', '__return_true' );
@jchristopher
jchristopher / functions.php
Created August 4, 2022 14:08
Enable 'Author' Info Column in OrganizeWP
<?php
// Enable 'Author' Info Column in OrganizeWP
// @link https://organizewp.com/docs/entries/#information-columns
add_filter( 'organizewp/post_type/info_columns/author', '__return_true' );
<?php
// Step 1: tell SearchWP to index Drafts, Pending, and Private entries in addition to its default post stati.
add_filter( 'searchwp\post_stati', function( $post_stati, $args ) {
$post_stati[] = 'draft';
$post_stati[] = 'pending';
$post_stati[] = 'private';
return $post_stati;
}, 20, 2 );
@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 / searchwp-customizations.php
Created April 27, 2021 00:12
Tell SearchWP to index both value and label from ACF Select field
<?php
// Tell SearchWP to index both value and label from ACF Select field.
add_filter( 'searchwp\source\post\attributes\meta', function( $meta_value, $args ) {
$acf_field_name = 'state'; // ACF Select field name.
if ( $acf_field_name !== substr( $args['meta_key'], strlen( $args['meta_key'] ) - strlen( $acf_field_name ) ) ) {
return $meta_value;
}
<?php
// Allow searching by WP_Post ID.
function swp14237_searchwp_results( $results, $attributes ) {
$search_query = get_search_query();
if ( ! is_numeric( $search_query ) ) {
return $results;
}
@jchristopher
jchristopher / searchwp-customizations.php
Last active April 1, 2021 19:10
Arbitrary SearchWP weight multiplier on date as Custom Field value
<?php
// Modify SearchWP calculated relevance using multiplier.
// @link https://searchwp.com/documentation/knowledge-base/add-relevance-weight-date/
class My_SearchWP_Date_Modifier {
private $post_type = 'post';
private $meta_key = 'event_date';
private $modifier_past = 0.5;
private $modifier_future = 1.5;
private $alias = 'myswpdm';
@jchristopher
jchristopher / searchwp-customizations.php
Created March 26, 2021 16:26
searchwp\auto_update_providers hook example
<?php
// Tell SearchWP to automatically update its providers when switching sites.
// @link https://searchwp.com/documentation/hooks/searchwp-auto_update_providers/
add_filter( 'searchwp\auto_update_providers', '__return_true' );
// Retrieve results from this site.
$searchwp_site_1 = new \SWP_Query( [
's' => 'coffee',
] );
@jchristopher
jchristopher / searchwp-customizations.php
Last active March 31, 2021 22:38
Enfold theme live search integration with SearchWP (version 4 and version 3)
<?php
// **********************************************************************//
// Enfold Search WP integration */
// **********************************************************************//
add_filter( 'avf_ajax_search_function', 'avia_init_searchwp', 10, 4 );
function avia_init_searchwp( $function_name, $search_query, $search_parameters, $defaults ) {
$function_name = class_exists( 'SWP_Query' ) ? 'avia_searchwp_search' : $function_name;
return $function_name;