-
Notifications
You must be signed in to change notification settings - Fork 124
Post select field
Robert O'Rourke edited this page Feb 6, 2015
·
12 revisions
Post select field. Displays a select input allowing the user to select a post.
Use the 'query' argument to modify the posts that will be available as options. See the documentation on WP Query for more information.
If the 'use_ajax' argument is set to true, the options are populated by an AJAX request when the select field is first clicked.
The value stored is the post ID.
Uses Select2, a jQuery based replacement for select boxes.
- id (string) (required)
- type 'post_select' (required)
- name (string) Field display name. Used as field label.
- query (array) WP_Query args.
- use_ajax (bool)
- allow_none (bool) Add an extra "None" option (only applies when not using the Ajax select)
- multiple (bool) When true allows selection of multiple posts
array(
'id' => 'example-field-post-select',
'name' => 'Post Select Field',
'type' => 'post_select',
'use_ajax' => true,
'query' => array(
'cat' => 8
)
);
The Post Select Field stores a post ID. See the example code for more information:
$saved_post_id = get_post_meta( get_the_id(), 'example-field-post-select', true );
echo get_the_title( $saved_post_id );
- Setup/Install Custom Meta Boxes
- Creating a custom meta box
- Displaying Field Data
- Optional Generic Field Args
- Repeatable Fields
General
- Text Field
- Small Text Field
- Number Field
- URL Field
- Textarea Field
- Code Field
- Select Field
- Checkbox Input Field
- Radio Input Field
Date & Time
WordPress
Media
Utilities