Jump to content

Recommended way to check if the value of a field is an image or not?


saml
 Share

Recommended Posts

I'm creating a general function for batch import, for a site migration, and while looping through fields (field names) to be imported for a page, I need to check whether the field is an image (or other file type), so that it can be imported after the first pave save.

What would be the recommended way to check this, with PHP code?

Link to comment
Share on other sites

That's one solution, the other would have been to determine the field type through the page's template.

$tpl = wire('templates')->get($templatename);
if( $tpl->fields->get($fieldname)->type instanceof FieldtypeFile ) { /* true for file and image field types, import as file */ }
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...