Support

Account

Forum Replies Created

  • Good to know, and thanks for coming back to me!

    What about adding in a licence key if I don’t have access to the updates page? I know that licence keys can be included manually in the wp-config.php file, but this falls outside of the theme file structure so I wouldn’t be able to include this as part of my core theme files.

    Would I need to do manually add this licence key on a site-by-site basis, or would I simply be able to ignore adding any licence keys onto a site entirely, providing that each client has purchased their own copy of ACF Pro of course?

  • This has now been solved:

    if( have_rows('custom_post_types', 'option') ):
                while( have_rows('custom_post_types', 'option') ) : the_row();
            
                // ACF Custom Label Declarations
            
                $cpt_name_plural = esc_html__( '"' . get_sub_field('cpt_name_plural') . '"' );
                $cpt_name_single = esc_html__( '"' . get_sub_field('cpt_name_single') . '"' );
                $cpt_label_add_new = esc_html__( '"' . get_sub_field('cpt_label_add_new') . '"' );
                $cpt_label_add_new_item = esc_html__( '"' . get_sub_field('cpt_label_add_new_item') . '"' );
                $cpt_label_edit_item = esc_html__( '"' . get_sub_field('cpt_label_edit_item') . '"' );
                $cpt_label_new_item = esc_html__( '"' . get_sub_field('cpt_label_new_item') . '"' );
                $cpt_label_view_item = esc_html__( '"' . get_sub_field('cpt_label_view_item') . '"' );
                $cpt_label_search_items = esc_html__( '"' . get_sub_field('cpt_label_search_items') . '"' );
                $cpt_label_not_found = esc_html__( '"' . get_sub_field('cpt_label_not_found') . '"' );
                $cpt_label_not_found_in_trash = esc_html__( '"' . get_sub_field('cpt_label_not_found_in_trash') . '"' );
                $cpt_label_parent_item_colon = esc_html__( '"' . get_sub_field('cpt_label_parent_item_colon') . '"' );
                $cpt_label_all_items = esc_html__( '"' . get_sub_field('cpt_label_all_items') . '"' );
                $cpt_label_archives = esc_html__( '"' . 
            get_sub_field('cpt_label_archives') . '"' );
                $cpt_label_attributes = esc_html__( '"' . get_sub_field('cpt_label_attributes') . '"' );
                $cpt_label_insert_into_item = esc_html__( '"' . get_sub_field('cpt_label_insert_into_item') . '"' );
                $cpt_label_uploaded_to_this_item = esc_html__( '"' . get_sub_field('cpt_label_uploaded_to_this_item') . '"' );
                $cpt_label_featured_image = esc_html__( '"' . get_sub_field('cpt_label_featured_image') . '"' );
                $cpt_label_set_featured_image = esc_html__( '"' . get_sub_field('cpt_label_set_featured_image') . '"' );
                $cpt_label_remove_featured_image = esc_html__( '"' . get_sub_field('cpt_label_remove_featured_image') . '"' );
                $cpt_label_use_featured_image = esc_html__( '"' . get_sub_field('cpt_label_use_featured_image') . '"' );
                $cpt_label_menu_name = esc_html__( '"' . get_sub_field('cpt_label_menu_name') . '"' );
                $cpt_label_filter_items_list = esc_html__( '"' . get_sub_field('cpt_label_filter_items_list') . '"' );
                $cpt_label_items_list_navigation = esc_html__( '"' . get_sub_field('cpt_label_items_list_navigation') . '"' );
                $cpt_label_items_list = esc_html__( '"' . get_sub_field('cpt_label_items_list') . '"' );
                $cpt_label_name_admin_bar = esc_html__( '"' . get_sub_field('cpt_label_name_admin_bar') . '"' );
            
                // Register Custom Post Type
                $cpt_name = get_sub_field('cpt_name');
                $cpt_args = array(
                    'label' => $cpt_name,
                    'description' => '',
                    'public' => true,
                    'publicly_queryable' => true,
                    'show_ui' => true,
                    'show_in_rest' => false,
                    'rest_base' => '',
                    'has_archive' => true,
                    'show_in_menu' => true,
                    'exclude_from_search' => false,
                    'capability_type' => 'post',
                    'map_meta_cap' => true,
                    'hierarchical' => false,
                    'rewrite' => array( 'slug' => $cpt_name, 'with_front' => true ),
                    'query_var' => true,
                    'menu_position' => 5,
                    'menu_icon' => 'dashicons-admin-post',
                    'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields', 'comments' ),
                    'taxonomies' => array( 'category', 'post_tag' ),
                    'labels' => array(
                        'name' => $cpt_name_plural,
                        'singular_name' => $cpt_name_single,
                        'menu_name' => $cpt_label_menu_name,
                        'add_new' => $cpt_label_add_new,
                        'add_new_item' => $cpt_label_add_new_item,
                        'edit_item' => $cpt_label_edit_item,
                        'new_item' => $cpt_label_new_item,
                        'view_item' => $cpt_label_view_item,
                        'search_items' => $cpt_label_search_items,
                        'not_found' => $cpt_label_not_found,
                        'not_found_in_trash' => $cpt_label_not_found_in_trash,
                        'parent_item_colon' => $cpt_label_parent_item_colon,
                        'all_items' => $cpt_label_all_items,
                        'archives' => $cpt_label_archives,
                        'attributes' => $cpt_label_attributes,
                        'insert_into_item' => $cpt_label_insert_into_item,
                        'uploaded_to_this_item' => $cpt_label_uploaded_to_this_item,
                        'featured_image' => $cpt_label_featured_image,
                        'set_featured_image' => $cpt_label_set_featured_image,
                        'remove_featured_image' => $cpt_label_remove_featured_image,
                        'use_featured_image' => $cpt_label_use_featured_image,
                        'filter_items_list' => $cpt_label_filter_items_list,
                        'items_list_navigation' => $cpt_label_items_list_navigation,
                        'items_list' => $cpt_label_items_list,
                        'name_admin_bar' => $cpt_label_name_admin_bar
                    )
                );
                register_post_type( $cpt_name, $cpt_args );
            
                endwhile;
            endif;
  • I’ve done some A/B testing, and it looks as though none of the custom variables I’ve defined in my example code above are pulling through at all.

    For example, changing the output of the $cpt_slug variable to output a simple “post-type-name” string (instead of pulling through any ACF field data) results in the CPT not registering, but typing the exact same “post-type-name” string into the register_post_type action as shown below, does register the CPT (albeit without any of the custom labels I”m trying to get working):

    register_post_type( "post-type-name", $args );

    Additionally, the if / else statements defined for the $labels arrays aren’t working properly either.

    I know this because changing all of the $args lines to be written in their standard format without any variable or ACF field calls at all, results in the default else: variations pulling through instead.

    Note: None of the above information has solved my issue, but hopefully it will help clarify which parts of my code just aren’t working from the offset!

  • Thank you for the reply! I have now amended the code as per your suggestion but it still doesn’t seem to be registering my CPTs:

    Amended PHP Code

    Do you have any other ideas about why this code might not be running?

    If it helps add any context, this code is utilised in a separate, dedicated PHP file which has been called through as ‘require’ in my functions.php file.

  • I managed to solve this myself. According to this post, it looks as though array_unique doesn’t work with sub_field text strings on ACF. Instead, using an if !in_array command worked fine, as seen in the below example:

    if( have_rows('global_typography', 'option') ):
        while( have_rows('global_typography', 'option') ) : the_row();          
            // display your sub fields
            $custom_font_file = get_sub_field('global_custom_font_file');
            // compare current value in saved array
            if( !in_array( $custom_font_file, $PreValue ) )
                {
                print '@font-face {' . PHP_EOL;
                print 'font-family: '; the_sub_field('global_custom_font_family_name'); print ';' . PHP_EOL;
                print "src: url('"; the_sub_field('global_custom_font_file'); print "');" . PHP_EOL;
                print 'font-weight: normal;' . PHP_EOL;
                print '}' . PHP_EOL  . PHP_EOL;
                }
            // save value in array
            $PreValue[] = $custom_font_file;
        endwhile;
    endif;
Viewing 6 posts - 1 through 6 (of 6 total)