getolympus/olympus-dionysos-field-wordpress

WordPress field, this component is a part of the Olympus Dionysos fields.

v0.0.21 2020-04-02 17:27 UTC

README

Dionysos Wordpress Field

Olympus Component CodeFactor Grade Packagist Version MIT

This component is a part of the Olympus Dionysos fields for WordPress. It uses a duplicate findPosts WordPress custom modal to manage field.

composer require getolympus/olympus-dionysos-field-wordpress

Table of contents

Field initializationVariables definitionsTexts definitionAccepted typesRetrive dataRelease historyContributing

Field initialization

Use the following lines to add a wordpress field in your WordPress admin pages or custom post type meta fields:

return \GetOlympus\Dionysos\Field\Wordpress::build('my_wordpress_field_id', [
    'title'       => 'Which is your favourite post?',
    'default'     => [],
    'description' => 'Tell us which one did like this week.',
    'field'       => 'ID',
    'multiple'    => false,
    'type'        => 'post',
    'settings'    => [],

    /**
     * Texts definition
     * @see the `Texts definition` section below
     */
    't_addblock_title' => 'Click on the edit button',
    't_addblock_description' => 'Click on the "+" button to add your item.',
    't_addblocks_description' => 'Click on the "+" button to add a new item.',
    't_addblock_label' => 'Add',
    't_editblock_label' => 'Edit',
    't_removeblock_label' => 'Remove',

    't_modaltitle_label' => 'Choose a content',
    't_modalclose_label' => 'Close',
    't_modalsearch_label' => 'Search',
    't_modalsubmit_label' => 'Select',

    't_ajaxerror_label' => 'No item found',
]);

Variables definitions

Notes:

  • Set multiple to true to display checkboxes instead of radio buttons
  • field variable is used to let you retrieve the data you need, depending on type value (for example: in the 'type' => 'term' case, you'll get term_id by default)

Texts definition

Accepted types

Retrive data

Retrieve your value from Database with a simple get_option('my_wordpress_field_id', []) (see WordPress reference):

// Get wordpress from Database
$wordpress = get_option('my_wordpress_field_id', []);

if (!empty($wordpress)) {
    echo '<ul>';

    foreach ($wordpress as $post_id) {
        echo '<li>'.get_the_title($post_id).'</li>';
    }

    echo '</ul>';
}

Release history

Contributing

  1. Fork it (https://github.com/GetOlympus/olympus-dionysos-field-wordpress/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Built with ♥ by Achraf Chouk ~ (c) since a long time.