• Resolved LesTexas60

    (@lestexas60)


    I am sorry to bother you with this again, You look very busy with the updates you have been doing. You helped me let users choose a Post Form category by adding the Taxonomy fiield. This field shows every category posible and I wanted to restrict the choices to a few select categories. On some of the Post Forms I would even restrict the category to only 1 so I could set were their post was going to show. You mentioned before this would take a small bit of code. I do appreciate your plugin and all the help you provide to everyone. The help responses are very educational. Waiting for the Taxonomy code to restrict the choices to only a few categories.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter LesTexas60

    (@lestexas60)

    I found where I can set a single default Category and then hide that field if I want only 1 Category to apply. That being said, I still have not found how to limit the choices of Categorys to say, 3 possible Categories when WP has 12 defined Categories.

    Plugin Author Shabti Kaplan

    (@shabti)

    Hello @lestexas60

    Here is your code snippet.

    There are two functions. The first sets the default value to a category with the id if 18. The second shows only parent categories in the field.

    function my_acf_prepare_tax_field( $field ) {
    $field['default_value'] = 18;//id of your category
    return $field;
    }
    add_filter('acf/prepare_field/type=taxonomy', 'my_acf_prepare_tax_field', 10, 1);
    
    add_filter('acf/fields/taxonomy/query', 'my_acf_fields_taxonomy_query', 10, 3); function my_acf_fields_taxonomy_query( $args, $field, $post_id ) { 
    // Show only parent categories
     $args['parent'] = 0;
     return $args;
     }
    Thread Starter LesTexas60

    (@lestexas60)

    Thank you Shabti. Is there a way to only show 3 out of 10 main categories in a drop down or radio button box. I don’t use Child categories and I have about 12 different categories but on many of my fors, I onlt wanted to allow the use of 3 different categories. The only way I have found to do this is to set the default single category and then make 3 different forms with a different default for each.

    Plugin Author Shabti Kaplan

    (@shabti)

    Yes there is a way.

    I will write this code snippet when I get a chance

    Thread Starter LesTexas60

    (@lestexas60)

    Thank you, I will add this option to the suggestion area.

    Many of the other form plugins have this option but I like yours best and don’t want to change.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do I restrict the Categories in a Post Form?’ is closed to new replies.