From 1210809e4334b28b660f3c0fbd3aeeddf96fd8ef Mon Sep 17 00:00:00 2001 From: Ross Trottier Date: Thu, 17 Oct 2024 14:39:34 -0600 Subject: [PATCH] search by acf fields --- acf-extensions/search-acf.php | 61 +++++++++++++++++++ federated.php | 5 +- rest-api/get_dns_records_test.php | 4 ++ rest-api/provisioner_rest_api_extensions.php | 5 ++ ...federated_woocommerce_shared_functions.php | 4 ++ woocommerce/my_account_customizations.php | 5 ++ ...ew_subscription_set_to_needs_provision.php | 4 ++ woocommerce/processing_to_complete_order.php | 4 ++ woocommerce/thank_you_page_customizations.php | 4 ++ 9 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 acf-extensions/search-acf.php diff --git a/acf-extensions/search-acf.php b/acf-extensions/search-acf.php new file mode 100644 index 0000000..5e26f8a --- /dev/null +++ b/acf-extensions/search-acf.php @@ -0,0 +1,61 @@ +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' ); \ No newline at end of file diff --git a/federated.php b/federated.php index dd6e7c3..3d19b0d 100644 --- a/federated.php +++ b/federated.php @@ -3,7 +3,7 @@ /** * Plugin Name: Federated Computer E-Commerce * 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/processing_to_complete_order.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'); \ No newline at end of file +//include( plugin_dir_path( __FILE__ ) . 'rest-api/get_dns_records_test.php'); \ No newline at end of file diff --git a/rest-api/get_dns_records_test.php b/rest-api/get_dns_records_test.php index 0df4e47..929b08f 100644 --- a/rest-api/get_dns_records_test.php +++ b/rest-api/get_dns_records_test.php @@ -1,5 +1,9 @@ get_items() as $line_item ) { diff --git a/woocommerce/my_account_customizations.php b/woocommerce/my_account_customizations.php index 87440c9..ae43156 100644 --- a/woocommerce/my_account_customizations.php +++ b/woocommerce/my_account_customizations.php @@ -1,4 +1,9 @@ ID); } diff --git a/woocommerce/processing_to_complete_order.php b/woocommerce/processing_to_complete_order.php index 52de544..3797303 100644 --- a/woocommerce/processing_to_complete_order.php +++ b/woocommerce/processing_to_complete_order.php @@ -1,5 +1,9 @@