APC Category Dropdown and post editing

My setup:
I have an APC frontend form. Users can create new posts. The form has some mandatory fields, like title, category, textarea etc., and some optional ones.

The issue is about the category field. It’s a REQUIRED dropdown select field (no multiple choices).
The post creation feed has post editing enabled with the exclusion of title and category.
Post creation works well, category is set correctly.
Here comes the problem part.
When the user wants to edit his own post on the frontend the post creation form appears again. Remember, the title and category fields can’t be edited (no permission).
BUT the category field is empty (nothing selected). Since the category field is a REQUIRED field but empty the form can’t be submitted again after editing.

How can I make the category field keep its initial choice so the form can be submitted and doesn’t run into the REQUIRED fields submission error?
Or any other best practice advice?

Hi Andre. When using the Advanced Post Creation Add-On, you should not use any fields from the “Post Fields” section of the form builder. We explain the limitation in the documentation here:

Note: You cannot use Post Fields in Advanced Post Creation. This means the fields of Post Body; Post Category; Post Custom Field; Post Excerpt; Post Image; Post Tags; and Post Title are not for mapping in an Advanced Post Creation feed. Use Standard or Advanced fields instead. Refer to Advanced Post Creation vs Post Fields for additional information.

To provide a list of categories in a dropdown, please add a dropdown field from the Standard fields, and give it a Custom CSS Class: of ‘populate-categories’ on the Appearance tab:

Then use this code to dynamically populate it with categories from the site. You can use this approach:

Here’s what the code should look:

The code will apply to form 1. Update the form ID in the filters to match your form ID. See our documentation here for where to add the code:

If you have any questions, let us know.

Excellent. Thank you so much, Chris. Works very well.

One more question. I need to exclude 2 categories as choices from the dropdown select. How do I do that?

Hi Andre. You can edit the “get_categories” line, like this:

Existing line:
$categories = get_categories( array( 'hide_empty' => false ) );

Modified line (to exclude categories 17 and 26):
$categories = get_categories( array( 'hide_empty' => false, 'exclude' => array( 17, 26 ) ) );

Perfect. Thank you so much.