Support

Account

Home Forums Front-end Issues Filter Custom posts in a relationship field

Helping

Filter Custom posts in a relationship field

  • Hi,

    I created 2 CPT Resume and Recruitment, in the single-resume.php in addition to displaying the resume data, I’m adding a recruitment form with a relational field that should point to the current Resume Only. by using acf/fields/relationship/query/key=.

    but i only get “No matches found” even if I hard code the post id.

    function limit_post_relationships( $args, $field, $post_id ) {
      
      $meta_query = array(
        array(
          'key' => 'resume',
          'value' => '"3448"', /** the post id i want get filtred */
          'compare' => 'LIKE',)
      );
      $args['meta_query'] = $meta_query;
      // return
      return $args;
    }
    
    add_filter('acf/fields/relationship/query/key=field_6239a67c81592', 'limit_post_relationships', 10, 3);

    I’m including the relationship field setting

  • It is unclear to me where this field is located and how the post types are related.

    For the filter to work the relationship field you are filtering by would need to be on the “Resume” CPT.

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

You must be logged in to reply to this topic.