Controlling Your Own WP Custom Fields (3 posts)

  1. Equal Web Creative
    Posted 5 years ago #

    I have found this code:


    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?

  2. Equal Web Creative
    Posted 5 years ago #

    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>';
  3. equalmark
    Posted 4 years ago #

    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,

Topic Closed

This topic has been closed to new replies.

About this Topic