Support

Account

Home Forums General Issues Filtering in post object

Helping

Filtering in post object

  • Im currently trying to add a post_object field to a custom post type ‘course’
    The post_object (with key: field_foo) should display a filtered collection of the custom post type ‘course-group’.
    Showing all ‘course-group’ posts is not a problem, but I need to achieve the following:
    Each ‘product’ has a ‘courseid’ field key with an ID for that course.
    Furthermore each ‘product-type’ has a matching ‘field_courseid’ field matching a ‘product’ id.

    How can I display only the ‘course-group’ posts in the ‘post_object’ that match the current ‘course’?

    I had tried the following (with a hardcoded number), but it did not work:
    `
    function foofunc($args, $field, $post_id) {
    $args[‘meta_query’] = array(
    array(
    ‘key’ => ‘field_courseid’,
    ‘value’ => ‘6’,
    ‘compare’ => ‘==’,
    ),
    );
    return $args;
    }

    add_filter(‘acf/fields/post_object/query/key=field_foo’, ‘foofunc’, 10, 3);
    `

    Even worse, just adding a function that only returns $args already breaks the post_object, causing it to return only the normal posts (and not the wanted custom posts of ‘course-group’)

  • Are you saying that if you do this

    
    add_filter('acf/fields/post_object/query/key=field_foo', 'foofunc, 10, 3);
    function foofunc($args, $field, $post_id) {
      return $args;
    }
    

    that it breaks the field?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.