Queries for posts using get_posts()
.
See Many-to-Many Relationships for a powerful example of using Datasources.
-
Example 1: Post Datasource in Select Dropdown
$fm = new Fieldmanager_Select( [ 'name' => 'event', 'datasource' => new Fieldmanager_Datasource_Post( [ 'query_args' => [ 'post_type' => 'event', 'posts_per_page' => 20, ], ] ), ] ); $fm->add_meta_box( 'Event', 'post' );
-
Example 2: Post Datasource using Autocomplete Ajax Request
This example also leverages the "show edit link" feature, which displays an "Edit" link next to the post title (only after the post is saved/loaded).
$fm = new Fieldmanager_Autocomplete( [ 'name' => 'related_post', 'show_edit_link' => true, 'datasource' => new Fieldmanager_Datasource_Post( [ 'query_args' => [ 'post_type' => 'post' ], ] ), ] ); $fm->add_meta_box( 'Related Post', 'post' );