Support

Account

Home Forums Add-ons Repeater Field ACF Query Post Object in Repeater matching the Custom post

Unread

ACF Query Post Object in Repeater matching the Custom post

  • Is it possible to use the below meta query with a post object field inside a repeater?

    $related_articles = get_posts(array(
        'post_type' => 'post',
        'meta_query' => array(
            array(
                'key' => 'related_articles', // name of custom field
                'value' => '"' . get_the_ID() . '"',
                'compare' => 'LIKE'
            )
        )
    ));
    
    if( $related_articles ): 
        foreach( $related_articles as $article ): 
    
        // Do something to display the articles. Each article is a WP_Post object.
        // Example:
    
        echo $article->post_title;  // The post title
        echo $article->post_excerpt;  // The excerpt
        echo get_the_post_thumbnail( $article->ID );  // The thumbnail
    
        endforeach;
    endif;
Viewing 1 post (of 1 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.