Filtering Looper results by ACF Post Object field based on current post ID

  • Hi,

    I’m working on a setup with two custom post types: verkaufsobjekte (real estate objects) and aktuelles (news/updates).

    Each aktuelles post has an ACF Post Object field called zugehoriges_projekt that stores a reference to one verkaufsobjekte post. On the single template of each verkaufsobjekte post, I want to display only the aktuelles posts that are assigned to that specific object.

    **My setup:**
    – GenerateBlocks Pro
    – GeneratePress Pro
    – ACF Pro
    – Field type: Post Object

    What I’m trying to achieve:
    On the single verkaufsobjekte template, a Looper block that runs a query equivalent to:

    `php
    new WP_Query([
    ‘post_type’ => ‘aktuelles’,
    ‘meta_query’ => [
    [
    ‘key’ => ‘zugehoriges_projekt’,
    ‘value’ => get_queried_object_id(),
    ‘compare’ => ‘=’,
    ],
    ],
    ]);
    `

    My questions:
    Is there a PHP filter or hook available for the Looper block?
    Is there any other recommended approach within GenerateBlocks to achieve this dynamic meta query without custom page templates?

    Thanks in advance!

  • Hello,

    Are you using v1 or v2 blocks? I am asking because the filter name might be different!

  • I am using v2 blocks.

  • I would recommend using the Relationship field instead of the post object.

    You do not need to use custom code; with GB Pro and v2 query block, you can set the query type to post meta > relationship field name, and it will fetch the posts from the relationship field.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.