Support

Account

Home Forums Add-ons Repeater Field Make a query to a subfield?

Helping

Make a query to a subfield?

  • Hello everyone,

    I’m using ACF on a website where a user can search post via multiple criteria, when he submit the criteria i create a query and run wp-query. My problem is when i try to search by a sub field in a repeater because the query returns all post. At the moment the query look like:

    //Other fields before
        if($cast != NULL){
            $args["meta_query"][$i] = array(
                    'key'       => 'cast_and_credits',
                    'value'     => $cast,
                    'compare'   => 'LIKE',
                    'type'      => 'CHAR',
                );
            $i++;
        }
    
        if($keyword != NULL){
            $args["meta_query"][$i] = array(
                    'key'       => 'parole_chiave',
                    'value'     => $keyword,
                    'compare'   => 'LIKE',
                    'type'      => 'CHAR',
                );
            $i++;
        }
    return new WP_Query( $args );
    

    I’ve already seen your guide but I don’t understand how they can help me.

    Can someone help me?

    Thanks in advice

    Danilo

  • Hello again,

    After a while i edit my code now I have a filter with is activate when someone use the subfield:

    
        if($keyword != NULL){
            add_filter('posts_where', 'filter_subfield');
        }
    

    the filter is the same on the example (except for the field of course) and after the operation, it returns:

    
    AND wp_posts.post_type = 'film' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND ( ( wp_postmeta.meta_key LIKE 'keyword_1' AND CAST(wp_postmeta.meta_value AS CHAR) LIKE '%%' )
    

    but the query returns 0 posts. Any ideas on how to fix it?

    Thanks to anybody who helps me

    Danilo

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Make a query to a subfield?’ is closed to new replies.