Search code examples
wordpressroman-numeralsmeta-query

How to add filter to meta_query like finding only Roma Numeric


I have some situational problem with meta_query. Customer Search IV, but result is included prIVate (original word is private). I want to show only IV (roma numeric) included post. My meta_query search from Title, sub title and description in Custom plugin. I found REGEXP but I couldn't find a correct way to find Roam numeric from title, sub-title and description.

Customer can find only Roma Numeric also they can find any words etc.


    $args = array(
        'numberposts' => -1,
        'category' => 0,
        'orderby' => 'post_date',
        'order' => 'DESC',
        'meta_query' => array(
            'relation' => 'OR',
            array(
                'key' => 'title',
                'value' => $search_term,
                'compare' => 'LIKE',
            ),
            array(
                'key' => 'sub-title',
                'value' => $search_term,
                'compare' => 'LIKE',
            ),
            array(
                'key' => 'description',
                'value' => $search_term,
                'compare' => 'LIKE',
            )
        ),
        'post_type' => 'gallery',
        'post_status' => 'publish',
        'suppress_filters' => true
    );

    $posts = get_posts($args, ARRAY_A); 


Solution

  • I solved my problem using regex to Title, Description and sub title. It's not good idea still looking for best answer.

    $tempFlag = false;      
    foreach (explode(" ", $description) as $temp) {
                if (preg_match('/^(?=[MDCLXVI])M*(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$/', $temp)) {
    
                    if (in_array($temp, $romeNumber)) {
                        $tempFlag = true;
                    }
                }
            }