Home Forums Backend Issues (wp-admin) Adding an Image Field Programmically


Adding an Image Field Programmically

  • I inherited a project from another developer who used your plug in to create custom fields. I need to add a new field to the bottom that allows the user to select an image for the page they are creating for a custom area of the page. I attempted to duplicate the creation of the MyCustomFields function and add it an the last Array item but it keeps coming up as a text input on the edit screen. Any ideas what I am missing here? My section starts with the ‘//Add page image’ comment

    var $customFields =	array(
    "name"			=> "ContactPerson-address",
    "title"			=> "Contact Room Number & Building",
    "description"	=> "Enter the room number and building of the page contact. Click <a href=\"\" target=\"_blank\">here</a> for building abbreviations. {CONTACT_ADDRESS}",
    "type"			=> "textinput",
    "scope"			=>	array( "page" ),
    "capability"	=> "edit_pages"
    			//Add page image
    "name"			=> "ContactPerson-image",
    "title"			=> "Contact Image for Page",
    "description"	=> "Select an image to use for the contact for this page",
    "type"			=> "image",
    "scope"			=>	array( "page" ),
    "capability"	=> "edit_pages"
  • Sample PHP export for an image field named “test”:

    array (
    	'key' => 'field_51db3a97ed096',
    	'label' => 'test',
    	'name' => 'test',
    	'type' => 'image',
    	'save_format' => 'object',
    	'preview_size' => 'thumbnail',
    	'library' => 'all',

    I would be curious to hear about whether adding this array into your code produces an image field properly.

  • Hi @Wally

    Your code suggests that the previous developer has a custom function to register custom fields. That or their are using another plugin to ACF as some of the parameters are missing / different.

    I think some debugging is required from your end to see how the fields are registered with ACF

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Adding an Image Field Programmically’ is closed to new replies.