Skip to content

Latest commit

 

History

History
70 lines (50 loc) · 1.07 KB

post-object.mdx

File metadata and controls

70 lines (50 loc) · 1.07 KB

Post Object

A post picker with AJAX search. Stores one or more post IDs.


PHP API

Field::postObject(string $key): PostObjectField

Type-specific methods

->postType(string|array $types): static

Restrict search to specific post type(s).

->multiple(bool $m = true): static

Allow selecting multiple posts.

->returnFormat(string $format): static
Format Returns
'id' (default) int or int[]
'object' \WP_Post or \WP_Post[]

Storage

{ "related_case": 42 }
{ "related_posts": [12, 34, 56] }

Example

Field::postObject('related_case')
    ->label('Related Case Study')
    ->postType('case-study')
    ->returnFormat('object'),

Field::postObject('related_posts')
    ->label('Related Posts')
    ->postType(['post', 'article'])
    ->multiple()
    ->returnFormat('object'),

Template usage

@php $post = ctrlfield_get('related_case') @endphp

@if($post)
    <a href="{{ get_permalink($post->ID) }}">{{ $post->post_title }}</a>
@endif