Post Object field
Purpose
One post (or several, with Select Multiple) chosen with a search box: a related page, a featured product, the author's profile post.
Field type name
post_object
Settings
| Setting | Description |
|---|---|
| Instructions | Shown to editors below the field label. (max 2000 characters) |
| Post Types | Post types editors can choose from (e.g. ["page", "product"]). Empty = every public post type. |
| Post Status | Only offer posts with these statuses (e.g. ["publish"]). Empty = any status except trash and auto-draft. |
| Filter by Taxonomy | Only offer posts in one of these terms, written taxonomy:slug (e.g. category:news). Applies to the picker. |
| Select Multiple | Let editors choose more than one post; the value becomes a list. |
| Return Format | object (WP_Post) or id. |
| Translation | How the field behaves in other languages: translate, copy, copy_once or do_not_translate. Used on top-level fields when WPML is active. See WPML. |
| Width | Width on edit screens, to place fields side by side: 100 (full), 75, 66, 50, 33 or 25 (%). Phones always show full width. |
| Label per language | The label and instructions per language code while editing in that language. Set on the Translation tab when WPML is active. See WPML. |
PHP return value
WP_Post (or its ID), null when empty; with Select Multiple a list. Deleted or trashed posts are left out. With WPML, the translation in the current language is returned when it exists.
Example
$related = cafe_get_field( 'related_page' ); // WP_Post|null
if ( $related ) {
printf( '<a href="%s">%s</a>', esc_url( get_permalink( $related ) ), esc_html( get_the_title( $related ) ) );
}
Editing
A search box with a list that opens when it gets focus. The chosen items and the first 20 items of the list are printed with the edit screen,
so the list opens at once, with no request. When those 20 are all there is, typing
filters them in the browser (case- and accent-insensitive) and the server is never
asked. Longer lists are searched on the server as the editor types (debounced, 20 per
page, "Load more" for the next page) through
GET /cafe/v1/references?field={key}&search=…&page=…; the current list stays visible
with a "Searching…" row until the answer arrives. The object being edited is never
offered. See REST.