• Resolved Baumer

    (@samuel9)


    Using the Pods Framework, I have extended the WordPress media content type and added a relationship field that links to one or more pods (department). An image can be associated with multiple departments.

    How do I query this extended media type to return media that contains a given department? I have tried:

        $id = get_the_ID(); // the current department page
    
        $media_pods = pods('attachment', array(
            'where' => "t.departments.meta_value LIKE '%$id%'",
        ));

    and

        $id = get_the_ID(); // the current department page
    
        $params = array(
            'post_type'  => 'attachment',
            'posts_per_page' => 6,
            'meta_query' => array(
                array(
                    'key'     => 'departments', // Pods relationship field key
                    'value'   => '"' . $id . '"', // Ensure exact match
                    'compare' => 'LIKE',
                ),
            ),
        );
    
        $query = new WP_Query($params);

    Neither returns any results. Note: the relationship field departments can contain more than one department.

    Any tips are greatly appreciated!

Viewing 1 replies (of 1 total)
  • Plugin Support Paul Clark

    (@pdclark)

    Pods find()

    $media_pods = pods(
    'attachment',
    [
    'where' => sprintf(
    'departments.meta_value IN( %d )',
    get_the_ID()
    ),
    ]
    );

    WP_Query

    $query = new WP_Query(
    [
    'post_type' => 'attachment',
    'posts_per_page' => 6,
    'meta_query' => [
    [
    'key' => 'departments',
    'value' => get_the_ID(),
    'compare' => 'IN',
    ],
    ],
    ]
    );

    get_posts()

    $posts = get_posts(
    [
    'post_type' => 'attachment',
    'posts_per_page' => 6,
    'meta_query' => [
    [
    'key' => 'departments',
    'value' => get_the_ID(),
    'compare' => 'IN',
    ],
    ],
    ]
    );
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.