Support » Plugins » Hacks » Controlling Your Own WP Custom Fields

  • I have found this code:

    Control your own WordPress custom fields

    Which allows you to control your own custom fields and the way they are entered. It works really well, however like a number of others in the comments I would like to create a select options as well as the checkbox and text areas etc.

    Could someone point me in the right direction on how to do this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Answered by own question here! The code I have used is:

    Add the following in your Custom Field array:

    	"name"		=> "select",
    	"title"		=> "Select",
    	"description"	=> "",
    	"type"		=> "select",
    	"scope"		=>	array( "post", "page" ),
    	"options"		=>	array( "", "One", "Two" ),
    	"capability"	=> "manage_options"

    Then add the following as a new case select:

    case "select": {
    	// Select
    	echo '<label for="' . $this->prefix . $customField[ 'name' ] .'" style="display:inline;"><b>' . $customField[ 'title' ] . '</b></label>';
    	echo '<select name="' . $this->prefix . $customField[ 'name' ] . '">';
    	foreach ($customField[ 'options' ] as $option) {
    	echo '<option>' . $option . '</option>';
    	echo '</select>';

    I am using the above method to add meta boxes to the write post and page screens and it is working a treat. However I would like to add a new case select for giving a list of all WordPress users.

    This way whichever WordPress user is selected from the list will be stored as a custom field for that post or page.

    Could anyone point me in the right direction of how I might go about this? I have tried looking at wp_dropdown_users() which kind of does what I want but I cannot get this to then save as the custom field.

    Any help would be much appreciated and thanks in advance,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Controlling Your Own WP Custom Fields’ is closed to new replies.