Skip to Content
Menu

fuzzy_posts_where()

Fuzzy meta sub key finder (Used to query Advanced Custom Fields nested repeater fields).

PHP April 26, 2017

Usage

PHP
nebula()->fuzzy_posts_where($where)

Parameters

$where
(Required) (String) The custom where clause
Default: None

Parameter Notes

Use _%_ in the where string for the fuzzy logic.

Request or provide clarification »

Examples

PHP
'key' => 'dates_%_start_date'
Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Utilities/Utilities.php on line 784.

    1 Hook

    Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

    Filters
    "pre_nebula_fuzzy_posts_where"
    Need a new filter hook? Request one here.

    Actions
    This function has no action hooks available. Request one?

    Note: This function contains 1 to-do comment.

    PHP
            public function fuzzy_posts_where($where){
                $override = apply_filters('pre_nebula_fuzzy_posts_where', null, $where);
                if ( isset($override) ){return $override;}
    
                global $wpdb;
    
                if ( strpos($wpdb->remove_placeholder_escape($where), '_%_') > -1 ){ //@todo "Nebula" 0: Update strpos() to str_contains() in PHP8
                    $where = preg_replace(
                        "/meta_key = ([\'\"])(.+)_%_/",
                        "meta_key LIKE $1$2_%_",
                        $wpdb->remove_placeholder_escape($where)
                    );
                }
    
                return $where;
            }
    

    Override

    To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):

    PHP
    add_filter('pre_nebula_fuzzy_posts_where', 'my_custom_fuzzy_posts_where', 10, 2); //The last integer must be 1 more than the actual parameters
    function my_custom_fuzzy_posts_where($null, $where){ //$null is required, but can be ignored
        //Write your own code here
    
        return true; //Return true to prevent the original function from running afterwords
    }

    You can completely disable this PHP function with a single line actions:

    PHP
     add_filter('pre_nebula_fuzzy_posts_where', '__return_false');