Support

Account

Home Forums General Issues Cannot use filters

Solved

Cannot use filters

  • Hello,
    i’m trying to use ACF in my project; it seems good but i have a problem with filters.

    I have added a Field group adding a True/False field in Post type called “Show in news”.

    I have defined a new custom type called News and i need to insert a select field with
    only the Post that have flagged the “Show in news”.
    I cannot select them: there are no items in conditional logic because they are different
    field groups.

    Am i doing wrong anything or is it an ACF limitation?

    Thanks in advance and greetings
    c.

  • Hi @cdiscla,

    Assuming you use the relationship field for selecting the posts you can use this filter to modify the query to only fetch posts with show_in_news set to 1/true:
    http://www.advancedcustomfields.com/resources/acf-fields-relationship-query/

  • Thank you very much Jonathan,
    your response helped me a lot.

    Here is the code i’ve added in function.php and it runs fine:

    function my_relationship_query( $args, $field, $post )
    {
        $args["meta_key"]="show_in_news";
        $args["meta_value"]="1";
        return $args;
    }
    
    // filter for a specific field based on it's name
    add_filter('acf/fields/relationship/query/name=related_articles', 'my_relationship_query', 10, 3);
  • No problem @cdiscla

    glad it worked out fine! I hope it’s just formatting of the posting that makes your end quotation mark different (it would probably break the code).

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

The topic ‘Cannot use filters’ is closed to new replies.