Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Selector #155

Closed
erralb opened this issue Jul 11, 2022 · 3 comments
Closed

Image Selector #155

erralb opened this issue Jul 11, 2022 · 3 comments

Comments

@erralb
Copy link

erralb commented Jul 11, 2022

Hi there, how can you achieve an Image Selector field ?

https://www.acf-extended.com/features/fields/image-selector

@stevep
Copy link
Member

stevep commented Jul 13, 2022

There is a plain addField function. First parameter is the field name, the second is the field type, and the third is the array of arguments for field settings. You'll have to find out what the field type name is from the acfe library, but I believe it's acfe_image_selector.

So you could use the following:

$group->addField('my_field_name', 'acfe_image_selector', []);

I thought the addField function was documented in the wiki, but it appears not to be the case.

@erralb
Copy link
Author

erralb commented Jul 18, 2022

Thanks, I will try this and post a working example !

@erralb
Copy link
Author

erralb commented Jul 18, 2022

So in the end I used https://github.com/cyberwani/ACF-Image-Select instead of the ACF extended plugin.

To add the field :

            ->addField('zindex','image_select', [
                'image_path' => get_stylesheet_directory_uri().'/resources/images/zindex/',
                'choices' => [
                    '1' => 'z-index 18',
                    '2' => 'z-index 12',
                    '3' => 'z-index 14',
                    '4' => 'z-index 16',
                ]
            ])->setDefaultValue('1')

The images must be named 1.png, 2.png, 3.png and 4.png for this to work.

I also modified the ACF-Image-Select plugin in order to get the values instead of the images' path with the get_field() method, in a similar fashion as explained in this issue.

@erralb erralb closed this as completed Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants