Home Forums General Issues Relationship Field Entries Not Showing Reply To: Relationship Field Entries Not Showing

  • If it helps, here’s the filter that is working for Use Case 1. The Query Loop itself is configured to point to the Review CPT. Then a custom class (in this case, btc-writers-roles-relationship) is added to the Grid element under that. The PHP filter script is called when it sees the custom class name, plus the relationship field in the current Reviews CPT post (in this case, writers), and enables the block to reference fields to return and format in the block UI. Can you suggest changes that would make this work in “reverse” … the Use Case 2 above?

    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
        // find the block with <code>btc-writers-relationship</code>
        if (
            ! empty( $attributes['className'] ) &&
            strpos( $attributes['className'], 'btc-writers-relationship' ) !== false &&
            ! is_admin()
        ) {
            // get the relate post ID
            $queried_object = get_queried_object () ;
            $relationship = get_field( "writers", $queried_object );
            // Merge the current $query_args with the new args
            return array_merge( $query_args, array(
                'post__in' => $relationship,
            ) );
        return $query_args;
    }, 10, 2 );