Carbon_Fields\Field\Association_Field::get_options PHP Method

get_options() public method

Generate the item options for the relationship field.
public get_options ( ) : array
return array $options The selectable options of the relationship field.
    public function get_options()
    {
        $options = array();
        foreach ($this->types as $type) {
            if ($type['type'] === 'post') {
                // populate posts
                /**
                 * Filter the default query when fetching posts for a particular field.
                 *
                 * @param array $args The parameters, passed to get_posts().
                 */
                $filter_name = 'carbon_relationship_options_' . $this->get_name() . '_' . $type['type'] . '_' . $type['post_type'];
                $args = apply_filters($filter_name, array('post_type' => $type['post_type'], 'posts_per_page' => -1, 'fields' => 'ids', 'suppress_filters' => false));
                // fetch and prepare posts as relationship items
                $posts = get_posts($args);
                foreach ($posts as &$p) {
                    $p = array('id' => $p, 'title' => $this->get_title_by_type($p, $type['type'], $type['post_type']), 'type' => $type['type'], 'subtype' => $type['post_type'], 'label' => $this->get_item_label($p, $type['type'], $type['post_type']), 'is_trashed' => get_post_status($p) == 'trash', 'edit_link' => $this->get_object_edit_link($type, $p));
                }
                $options = array_merge($options, $posts);
            } elseif ($type['type'] === 'term') {
                // populate taxonomy terms
                /**
                 * Filter the default parameters when fetching terms for a particular field.
                 *
                 * @param array $args The parameters, passed to get_terms().
                 */
                $filter_name = 'carbon_relationship_options_' . $this->get_name() . '_' . $type['type'] . '_' . $type['taxonomy'];
                $args = apply_filters($filter_name, array('hide_empty' => 0, 'fields' => 'id=>name'));
                // fetch and prepare terms as relationship items
                $terms = get_terms($type['taxonomy'], $args);
                foreach ($terms as $term_id => &$term) {
                    $term = array('id' => $term_id, 'title' => $term, 'type' => $type['type'], 'subtype' => $type['taxonomy'], 'label' => $this->get_item_label($term_id, $type['type'], $type['taxonomy']), 'is_trashed' => false, 'edit_link' => $this->get_object_edit_link($type, $term_id));
                }
                $options = array_merge($options, $terms);
            } elseif ($type['type'] === 'user') {
                // populate users
                /**
                 * Filter the default parameters when fetching users for a particular field.
                 *
                 * @param array $args The parameters, passed to get_users().
                 */
                $filter_name = 'carbon_relationship_options_' . $this->get_name() . '_' . $type['type'];
                $args = apply_filters($filter_name, array('fields' => 'ID'));
                // fetch and prepare users as relationship items
                $users = get_users($args);
                foreach ($users as &$u) {
                    $u = array('id' => $u, 'title' => $this->get_title_by_type($u, $type['type']), 'type' => $type['type'], 'subtype' => 'user', 'label' => $this->get_item_label($u, $type['type']), 'is_trashed' => false, 'edit_link' => $this->get_object_edit_link($type, $u));
                }
                $options = array_merge($options, $users);
            } elseif ($type['type'] === 'comment') {
                // populate comments
                /**
                 * Filter the default parameters when fetching comments for a particular field.
                 *
                 * @param array $args The parameters, passed to get_comments().
                 */
                $filter_name = 'carbon_relationship_options_' . $this->get_name() . '_' . $type['type'];
                $args = apply_filters($filter_name, array('fields' => 'ids'));
                // fetch and prepare comments as relationship items
                $comments = get_comments($args);
                foreach ($comments as &$c) {
                    $c = array('id' => $c, 'title' => $this->get_title_by_type($c, $type['type']), 'type' => $type['type'], 'subtype' => 'comment', 'label' => $this->get_item_label($c, $type['type']), 'is_trashed' => false, 'edit_link' => $this->get_object_edit_link($type, $c));
                }
                $options = array_merge($options, $comments);
            }
        }
        /**
         * Filter the final list of options, available to a certain relationship field.
         *
         * @param array $options Unfiltered options items.
         * @param string $name Name of the relationship field.
         */
        $options = apply_filters('carbon_relationship_options', $options, $this->get_name());
        return $options;
    }