Skip to content
Matth_eu edited this page Sep 24, 2013 · 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.

Post Select Field

Uses Select2, a jQuery based replacement for select boxes.

Args

Required Args

  • id (string) (required)
  • type 'post_select' (required)
  • name (string) Field display name. Used as field label.

Field Specific Args

  • query (array) WP_Query args.
  • use_ajax (bool)
  • allow_none (bool) Add an extra "None" option (only applies when not using the Ajax select)

Optional Generic Args

See Optional Generic Args

Example Usage

array( 
	'id'       => 'example-field-post-select', 
	'name'     => 'Post Select Field', 
	'type'     => 'post_select', 
	'use_ajax' => true,
	'query' => array( 
		'cat' => 8
	)
);

Using the Data

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 );