0

I'm working on a relationship filter using this documentary.

I made so far but can't make my return value. Normally in a custom Template I just echo it, but it's different in a function I think.

function soup_filter( $args, $field, $post_id ) {

$args = array('post_type' => 'menu');
$query = new WP_Query( $args );

$soups = get_field('soups');

foreach ($soups as $soup) {
    //return value stored here in $soup
}


// return
return $args;
}
add_filter('acf/fields/relationship/query/key=field_59f736725fe5d', 'soup_filter', 10, 3);
3
  • Does your $soups return something ?
    – Elex
    Dec 22 '17 at 10:17
  • Yes it'll return all the soup categorized post types
    – DeluxeD
    Dec 22 '17 at 10:39
  • During the loop, are you using return ? Do you perform some actions to $args ?
    – Elex
    Dec 22 '17 at 10:40
0

I am not sure it is supposed to work like this. Maybe try calling the get_field like this. If the get_field is not called within the loop, it needs the post_id parameter

$soups = get_field('soups', $post_id )
0

Well, I'm not sure what you are trying to echo but that's a filter, which means that it takes a value $args and allows you to process it and then return it back(<-a general overview of a filter). This means that you cannot echo in there.

From the ACF's documentation that you provided:

This hook allows you to modify the $args array which is used to query the posts shown in the relationship field list.

This filter just allows you to change the rules of the query which brings posts in the relationship selector.

Also, you don't need to get other $soups; you already have the $field passed as the second function parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.