Support

Account

Home Forums Add-ons Repeater Field Reverse relationshiop query from repeater field

Solving

Reverse relationshiop query from repeater field

    • Sagi

    • May 25, 2021 at 9:06 pm

    Hi i have a repeater field with relationship in it and i want to query all post which are connected from those relationship sub fields to current post. I’ve been going through documentation and forum but i can’t get it working.

    Code with which i ended up for now:

    function my_posts_where( $where ) {
                $where = str_replace( "meta_key = 'wystawcy_$", "meta_key LIKE 'wystawcy_%", $where );
                return $where;
              }
    
              add_filter( 'posts_where', 'my_posts_where' );
    
              $doctors = get_posts( array(
                'numberposts' => -1,
                'post_type' => 'any',
                'meta_query' => array(
                  array(
                    'key' => 'wystawcy_$_kategoria_wystawcy',
                    'value' => '"' . get_the_ID() . '"',
                    'compare' => '=',
                  )
                )
              ) );
    		
              print_r( $doctors );
    
              if ( $doctors ):
                foreach ( $doctors as $doctor ):
    
                  echo get_the_title( $doctor->ID );
    
              endforeach;
              endif;

    wystawcy – is a repeater field
    kategoria_wystawcy – is a relationship field

  • 
    
                'meta_query' => array(
                  array(
                    'key' => 'wystawcy_$_kategoria_wystawcy',
                    'value' => '"' . get_the_ID() . '"',
                    'compare' => 'LIKE',
                  )
    
    • Sagi

    • May 28, 2021 at 5:30 pm

    I’ve tried with LIKE but results is same, an empty array 🙁

  • I could be missing it, but I don’t see anything else wrong with your query.

Viewing 4 posts - 1 through 4 (of 4 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.