Support

Account

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

Solving

Adding an Image Field Programmically

    • Wally

    • July 9, 2013 at 12:14 am

    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(
    array( 
    "name"			=> "ContactPerson-address",
    "title"			=> "Contact Room Number & Building",
    "description"	=> "Enter the room number and building of the page contact. Click <a href=\"http://www.engin.umich.edu/buildingabbreviations\" target=\"_blank\">here</a> for building abbreviations. {CONTACT_ADDRESS}",
    "type"			=> "textinput",
    "scope"			=>	array( "page" ),
    "capability"	=> "edit_pages"
    ),
    	
    			//Add page image
    array( 
    "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.

    • Elliot

    • July 9, 2013 at 10:12 am

    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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.