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);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.