Last active
September 30, 2020 16:44
-
-
Save jchristopher/dcdb0a50047041b121cb8689d6d1f6e0 to your computer and use it in GitHub Desktop.
Include WooCommerce Product Drafts in SearchWP Admin Searches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add Drafts to Products when indexing and searching in Admin. | |
add_filter( 'searchwp\post_stati\product', function( $stati ) { | |
$stati[] = 'draft'; | |
$stati[] = 'private'; | |
return $stati; | |
}, 30 ); | |
// Remove Drafts from front end searches. | |
add_action( 'searchwp\query\before', function() { | |
if ( ! ( is_admin() && ! wp_doing_ajax() ) ) { | |
add_filter( 'searchwp\query\mods', function( $mods ) { | |
$mod = new \SearchWP\Mod( | |
\SearchWP\Utils::get_post_type_source_name( 'product' ) | |
); | |
$mod->set_where( [ [ | |
'column' => 'post_status', | |
'value' => [ 'draft', 'private' ], | |
'compare' => 'NOT IN', | |
] ] ); | |
$mods[] = $mod; | |
return $mods; | |
} ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment