class Fieldmanager_Datasource_Post extends Fieldmanager_Datasource (View source)

Datasource to populate autocomplete and option fields with WordPress Posts.

Properties

array $options

The datasource options.

from  Fieldmanager_Datasource
string $options_callback

Options callback.

from  Fieldmanager_Datasource
bool $use_ajax

Allow Ajax. If set to false, Autocomplete will pre-load get_items() with no fragment, so False could cause performance problems.

bool $allow_optgroups

Allow option groups.

from  Fieldmanager_Datasource
string $ajax_action

The Ajax action.

from  Fieldmanager_Datasource
static int $counter

Counter to create uniquely named Ajax actions.

from  Fieldmanager_Datasource
bool $grouped

If true, group elements.

from  Fieldmanager_Datasource
null $query_callback

Supply a function which returns a list of posts; takes one argument, a possible fragment.

array $query_args

Arguments to get_posts(), which uses WP's defaults, plus suppress_filters = False, which can be overridden by setting suppress_filters = True here.

string $reciprocal

If not empty, set this post's ID as a value on the linked post. This is used to establish two-way relationships.

bool $show_date

Display the post publish date in the typeahead menu.

string $date_format

If $show_date is true, the format to use for displaying the date.

bool $publish_with_parent

Publish the child post when/if the parent is published.

bool $save_to_post_parent

Save to post parent.

bool $only_save_to_post_parent

Only save to post parent.

Methods

__construct(array $options = array())

Construct the object.

string
get_value(int $value)

Get a post title by post ID.

array
get_items(string $fragment = null)

Get posts which match this datasource, optionally filtered by a fragment, e.g. for Autocomplete.

string
get_ajax_action()

Get an action to register by hashing (non cryptographically for speed) the options that make this datasource unique.

get_items_for_ajax(string|null $fragment = null)

Format items for use in Ajax.

autocomplete_search()

Ajax callback to find posts.

string
presave_alter_values(Fieldmanager_Field $field, mixed $values, mixed $current_values)

For post relationships, delete reciprocal post metadata prior to saving (presave will re-add).

array
preload_alter_values(Fieldmanager_Field $field, mixed $values)

Preload alter values for post parent The post datasource can store data outside FM's array.

string
presave(Fieldmanager_Field $field, mixed $value, mixed $current_value)

Handle reciprocal postmeta and post parents.

string
get_view_link(mixed $value)

Get edit link for a post.

string
get_edit_link(int|string $value)

Get edit link for a post.

title_like(string $where, WP_Query $wp_query)

Perform a LIKE search on post_title, since 's' in WP_Query is too fuzzy when trying to autocomplete a title.

presave_status_transition(Fieldmanager_Field $field, int $value)

Handle any actions based on the parent's status transition.

Details

__construct(array $options = array())

Construct the object.

Parameters

array $options

The datasource options.

string get_value(int $value)

Get a post title by post ID.

Parameters

int $value

Post ID.

Return Value

string

The value.

array get_items(string $fragment = null)

Get posts which match this datasource, optionally filtered by a fragment, e.g. for Autocomplete.

Parameters

string $fragment

Optional fragment to filter by.

Return Value

array

The key => value of available options.

string get_ajax_action()

Get an action to register by hashing (non cryptographically for speed) the options that make this datasource unique.

Return Value

string

Ajax action.

get_items_for_ajax(string|null $fragment = null)

Format items for use in Ajax.

Parameters

string|null $fragment

Search string.

Ajax callback to find posts.

string presave_alter_values(Fieldmanager_Field $field, mixed $values, mixed $current_values)

For post relationships, delete reciprocal post metadata prior to saving (presave will re-add).

Parameters

Fieldmanager_Field $field

Base field.

mixed $values

New value.

mixed $current_values

Current value.

Return Value

string

$values Cleaned value.

array preload_alter_values(Fieldmanager_Field $field, mixed $values)

Preload alter values for post parent The post datasource can store data outside FM's array.

This is how we add it back into the array for editing.

Parameters

Fieldmanager_Field $field

Base field.

mixed $values

New values.

Return Value

array

$values Loaded up, if applicable.

string presave(Fieldmanager_Field $field, mixed $value, mixed $current_value)

Handle reciprocal postmeta and post parents.

Parameters

Fieldmanager_Field $field

Base field.

mixed $value

New value.

mixed $current_value

Current value.

Return Value

string

$values Cleaned value.

Get edit link for a post.

Parameters

mixed $value

The current value.

Return Value

string

HTML string.

Get edit link for a post.

Parameters

int|string $value

The current value.

Return Value

string

HTML string.

title_like(string $where, WP_Query $wp_query)

Perform a LIKE search on post_title, since 's' in WP_Query is too fuzzy when trying to autocomplete a title.

Parameters

string $where

The where clause.

WP_Query $wp_query

The reference to the query object.

presave_status_transition(Fieldmanager_Field $field, int $value)

Handle any actions based on the parent's status transition.

Parameters

Fieldmanager_Field $field

The parent.

int $value

The child post id.