Support

Account

Home Forums Front-end Issues Query custom post type depending on post object inside a repeater Reply To: Query custom post type depending on post object inside a repeater

  • Hi @cedric_charles

    Then you need to build the query for each lawyer ID. I believe it should be something like this:

    // initialize the meta query
    $meta_query = array('relation' => 'OR');
    
    // Add the query for each lawyer ID
    foreach( $lawyers_ids as $lawyers_id ) {
        $meta_query[] array(
            'key' => 'book_authors',
            'value' => '"' . $lawyers_id . '"',
            'compare' => 'LIKE'
        );
    }
    
    // Get the books
    $books = get_posts(array(
        'post_type' => 'book',
        'paged' => $paged,
        'posts_per_page' => -1,
        'meta_query' => $meta_query,
    ));

    I hope this helps 🙂