search by acf fields

This commit is contained in:
Ross Trottier 2024-10-17 14:39:34 -06:00
parent b2a31d8521
commit 1210809e43
9 changed files with 94 additions and 2 deletions

View File

@ -0,0 +1,61 @@
<?php
if( ! defined( 'ABSPATH' ) ){
exit; // Exit if accessed directly.
}
/**
* Extend WordPress search to include custom fields
*
* https://adambalee.com
*/
/**
* Join posts and postmeta tables
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
*/
function cf_search_join( $join ) {
global $wpdb;
if ( is_search() ) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
add_filter('posts_join', 'cf_search_join' );
/**
* Modify the search query with posts_where
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where
*/
function cf_search_where( $where ) {
global $pagenow, $wpdb;
if ( is_search() ) {
$where = preg_replace(
"/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
}
return $where;
}
add_filter( 'posts_where', 'cf_search_where' );
/**
* Prevent duplicates
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_distinct
*/
function cf_search_distinct( $where ) {
global $wpdb;
if ( is_search() ) {
return "DISTINCT";
}
return $where;
}
add_filter( 'posts_distinct', 'cf_search_distinct' );

View File

@ -3,7 +3,7 @@
/** /**
* Plugin Name: Federated Computer E-Commerce * Plugin Name: Federated Computer E-Commerce
* Description: This plugin contains customizations for Federated Computer. * Description: This plugin contains customizations for Federated Computer.
* Version: 1.0.5 * Version: 1.1.0
*/ */
@ -17,5 +17,6 @@ include( plugin_dir_path( __FILE__ ) . 'rest-api/provisioner_rest_api_extensions
include( plugin_dir_path( __FILE__ ) . 'woocommerce/new_subscription_set_to_needs_provision.php'); include( plugin_dir_path( __FILE__ ) . 'woocommerce/new_subscription_set_to_needs_provision.php');
include( plugin_dir_path( __FILE__ ) . 'woocommerce/processing_to_complete_order.php'); include( plugin_dir_path( __FILE__ ) . 'woocommerce/processing_to_complete_order.php');
include( plugin_dir_path( __FILE__ ) . 'shared/federated_woocommerce_shared_functions.php'); include( plugin_dir_path( __FILE__ ) . 'shared/federated_woocommerce_shared_functions.php');
include( plugin_dir_path( __FILE__ ) . 'acf-extensions/search-acf.php');
include( plugin_dir_path( __FILE__ ) . 'rest-api/get_dns_records_test.php'); //include( plugin_dir_path( __FILE__ ) . 'rest-api/get_dns_records_test.php');

View File

@ -1,5 +1,9 @@
<?php <?php
if( ! defined( 'ABSPATH' ) ){
exit; // Exit if accessed directly.
}
add_action('rest_api_init', 'federated_route_get_dns'); add_action('rest_api_init', 'federated_route_get_dns');
function federated_route_get_dns(){ function federated_route_get_dns(){

View File

@ -1,4 +1,9 @@
<?php <?php
if( ! defined( 'ABSPATH' ) ){
exit; // Exit if accessed directly.
}
//Get needs provision, get needs removal //Get needs provision, get needs removal
add_action('rest_api_init', 'federated_route_update_provision_status_failed_register'); add_action('rest_api_init', 'federated_route_update_provision_status_failed_register');

View File

@ -1,5 +1,9 @@
<?php <?php
if( ! defined( 'ABSPATH' ) ){
exit; // Exit if accessed directly.
}
function get_subscription_tier($subscription){ function get_subscription_tier($subscription){
$tier = ''; $tier = '';
foreach ( $subscription->get_items() as $line_item ) { foreach ( $subscription->get_items() as $line_item ) {

View File

@ -1,4 +1,9 @@
<?php <?php
if( ! defined( 'ABSPATH' ) ){
exit; // Exit if accessed directly.
}
/** /**
* @snippet WooCommerce Add Provision Info Tab * @snippet WooCommerce Add Provision Info Tab
* @author Ross Trottier * @author Ross Trottier

View File

@ -1,5 +1,9 @@
<?php <?php
if( ! defined( 'ABSPATH' ) ){
exit; // Exit if accessed directly.
}
function federated_set_new_subscription_provision_status($subscription){ function federated_set_new_subscription_provision_status($subscription){
update_field('provision_status', 'needs_provision', $subscription->ID); update_field('provision_status', 'needs_provision', $subscription->ID);
} }

View File

@ -1,5 +1,9 @@
<?php <?php
if( ! defined( 'ABSPATH' ) ){
exit; // Exit if accessed directly.
}
add_action('woocommerce_payment_complete', 'federated_set_new_order_to_complete'); add_action('woocommerce_payment_complete', 'federated_set_new_order_to_complete');
function federated_set_new_order_to_complete($order_id) function federated_set_new_order_to_complete($order_id)

View File

@ -1,5 +1,9 @@
<?php <?php
if( ! defined( 'ABSPATH' ) ){
exit; // Exit if accessed directly.
}
add_action( 'woocommerce_before_thankyou', 'federated_thank_you_page_message' ); add_action( 'woocommerce_before_thankyou', 'federated_thank_you_page_message' );
function federated_thank_you_page_message( $order_id ) { function federated_thank_you_page_message( $order_id ) {