Support

Account

Home Forums Add-ons Repeater Field Query subrepeater field inside a group field

Solving

Query subrepeater field inside a group field

    • yarongo

    • December 17, 2020 at 8:53 pm

    I have a set of fields in a repeater that in a group field.
    I’m tring to search a name in that repeater from all the posts i have in “projects” custom post that attached to a specific “customer”

    more_details – group field
    professionals – repeater
    professional_name – subfield which i need to search on

    I tried this:

    function my_posts_where( $where ) {
    	$where = str_replace("meta_key = 'more_details_$_professionals_$_professional_name'", "meta_key LIKE 'more_details_%_professionals_%_professional_name'", $where);
    	return $where;
    }
    add_filter('posts_where', 'my_posts_where');
    
    $searchKey = $_POST['searchKey'];
    $customerID = $_POST['customerID'];
    
    $args = array(
    'post_type' => 'projects',
    'posts_per_page' => -1,
    		'meta_query'	=> array(
    		'relation'		=> 'AND',
    		array(
    			'key'		=> 'customer',
    			'compare'	=> '=',
    			'value'		=> $customerID,
    		),
    		array(
    			'key'		=> 'more_details_$_professionals_$_professional_name',
    			'compare'	=> 'LIKE',
    			'value'		=> $searchKey,
    		)
    	)
        );
    	
    $query = new WP_Query( $args );
    if( $query->have_posts() )....
  • group fields do not have indexes, the meta key should be

    
    more_details_professionals_$_professional_name
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.