Support

Account

Home Forums Backend Issues (wp-admin) Hide taxonomy term in Form and in post

Solved

Hide taxonomy term in Form and in post

  • Hi,

    I have added an ACF checkbox for taxonomy term, checked equals HIDDEN.
    In ACF form and post edit page, i need to hide the term in Dropdown if the chekbox is checked.
    By the way i need also to hide all the post that have this taxonomy term.

    Example:
    Post : Movie
    Taxonomy: Genre
    Taxonomy term : Action
    Action is Checked – > Hide “Action” in ACF form dropdown, edit movie page , and all the action movie in backend.

    thanks

  • i have tried this, but it does no work:

    // exclude categories from category dropdown
    add_filter('acf/fields/taxonomy/query/name=materiel_client', 'exclude_categories', 10, 2);
    function exclude_categories( $args, $field ) {
      $terms = get_terms([
        'taxonomy' => 'materiel_client',
        'hide_empty' => false,
    ]);
    
    $excluding = array();
     foreach ($terms as $term)
     {
     // $temp.=get_field ( 'visibilite', $term->term_id  );
     
     if (get_post_meta( $term->term_id , 'visibilite')=='oui'){
     array_push($excluding , get_post_meta( $term->term_id , 'visibilite'));
     }
     }
     
       $args['exclude'] = $excluding; //the IDs of the excluded terms
      return $args;
    }
  • actually get_field ( ‘visibilite’, $term->term_id ) is empty and also get_post_meta( $term->term_id , ‘visibilite’)

    the value is in databae :
    https://snipboard.io/HLsJIG.jpg

  • You need to use

    
    get_field('visibilite', 'term_'.$term->term_id)
    

    OR

    
    get_field('visibilite', $term)
    

    OR

    
    get_term_meta($term->term_id, 'visibilite', true)
    
  • Thanks a lot !

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

The topic ‘Hide taxonomy term in Form and in post’ is closed to new replies.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.