• This thread is for self-documenting an issue i’m encountering.

    I am using WP User Groups with a couple of groups.

    I am also using Advanced Custom Fields, and I am generating form fields with a custom function, as explained in the ACF documentation.

    In that form, I try to make use of WP User Groups data, with query such as this (‘user-group’ being one of the default WP User Groups taxonomies):

    $all_user_groups = get_terms( array(
    	    'taxonomy' => 'user-group', 
    	    'hide_empty' => true,
    ) );

    In other contexts this is working, but inside my ACF-form-building function, it returns nothing at all. The function is linked to the action ‘acf/init’, as recommended in the ACF docs. My assumption is that this action occurs too early in the load sequence, and the WP User Groups aren’t defined yet at that point.

    The question then is: what is the appropriate action to use?

Viewing 1 replies (of 1 total)
  • Thread Starter Manuel Schmalstieg

    (@targz-1)

    After looking at the Action Reference, it’s quite easy to find a working solution.

    What doesn’t work:

    – Using ‘acf/init’
    – Using the ‘init’ action with the default priority (10).

    What works:

    – Using ‘init’ with a lower priority (anything higher than 10), such as: add_action('init', 'my_custom_function', 20);
    – Using ‘wp_loaded’: add_action('wp_loaded', 'my_custom_function');
    – Using ‘admin_init’: add_action('admin_init', 'my_custom_function');

    So it appears that WP User Groups are being defined at the ‘init’ step, “typically used by plugins to initialize”.

Viewing 1 replies (of 1 total)
  • The topic ‘At what point in the load sequence are User Groups registered?’ is closed to new replies.