Support

Account

Home Forums Backend Issues (wp-admin) How can I filter a posts relationship field by the current category edit screen? Reply To: How can I filter a posts relationship field by the current category edit screen?

  • Needed this today, and found the solution.

    Here it is in case someone needs it:

    function limit_cat_post_relationships( $title, $post3, $field, $post_id  )
    {
        /* Because this is proccesd as an AJAX request
         * we can get the referer, and extract the tag_ID from there
         */
        
        $url     = wp_get_referer();
        $parts   = parse_url($url);
        parse_str($parts['query'], $query);
    
        $title['tax_query'][0]['terms'][0] = $query['tag_ID']; 
        return $title;
    }
    add_filter('acf/fields/relationship/query/name=ibm_topic_feat_posts', 'limit_cat_post_relationships', 10, 3);