Support

Account

Home Forums General Issues Querying a Post Object relation field inside a repeater Reply To: Querying a Post Object relation field inside a repeater

  • Hi @charlesr

    It seems that you forgot to add the functions to change the SQL query. Could you please check the link I gave you again (please check the section “4. Sub custom field values”)?

    I believe you need to do it like this:

    // filter
    function my_posts_where( $where ) {
    	
    	$where = str_replace("meta_key = 'person_department_%", "meta_key LIKE 'person_department_%", $where);
    
    	return $where;
    }
    add_filter('posts_where', 'my_posts_where');
    
    // args
    $args = array(
        'numberposts'	=> -1,
        'post_type'		=> 'people',
        'meta_query'	=> array(
            'relation'		=> 'AND',
            array(
                'key'		=> 'person_department_%_person_department_select', // this should be the first sub-field
                'value' => get_the_ID(),
                'compare' => '='
            ),
            array(
                'key'		=> 'person_department_%_person_department_head', // this should be the second sub-field
                'value' => true,
                'compare' => '='
            )
        )
    );

    I hope this helps 🙂