Contributors: Mati Kärner
Tags: ACF, AJAX
Requires at least: 3.7
Tested up to: 4.7.4
Stable tag: 1.2.1
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
Connect external entitites via ACF Relationship field
Connect external entitites via ACF Relationship field. Tested with ACF 5.5.* - 5.5.12.
How to install the plugin and get it working:
-
Upload folder to the
/wp-content/plugins/
directory -
Activate the plugin through the 'Plugins' menu in WordPress
-
Use filters to poulate post selector with values.
class DataSource { protected $args; public function __construct($args = array()) { $this->args = array_merge ( array ( 'name' => 'myFieldName' ), $args ); $this->setUpHooksAndFilters (); } protected function setUpHooksAndFilters() { $filter_pre = sprintf ( 'acf/fields/%s', 'external_relationship' ); $filter_after = sprintf ( 'name=%s', $this->args ['name'] ); $tag = function ($name, $after = true) use ($filter_pre, $filter_after) { return sprintf ( '%s/%s%s', $filter_pre, $name, $after ? $filter_after : '' ); }; // Results add_filter ( $tag ( 'fetch' ), array ( $this, 'getEntities' ), 10, 2 ); // Title for ID-s add_filter ( $tag ( 'result' ), array ( $this, 'getTitle' ), 10, 5 ); // Tags (no filter for name/key) add_filter ( $tag ( 'query_tags', false ), array ( $this, 'getTags' ), 10, 2 ); // Types (no filter for name/key) add_filter ( $tag ( 'query_types', false ), array ( $this, 'getTypes' ), 10, 2 ); } public function doQuery($args) { $entities = array (); // Return array of objects: $id = 'myID'; $entities [$id] = new \stdClass (); $entities [$id]->ID = $id; $entities [$id]->name = 'Name'; return $entities; } public function getEntities($entities, $args) { $entities = $this->doQuery ( $args ); return $entities; } public function getTitle($title, $entity, $field, $post_id, $is_search) { return $entity->name; } public function getTags($tags, $field) { // TODO FIXME return $tags; } public function getTypes($types, $field) { // TODO FIXME return $types; } } // Init (e.g. In themes/plugins functions.php) add_action('init', function () { global $dataSource; $dataSource = new DataSource(); })
An answer to that question.
- Fixes for filters governing Types
- Fixes for filters governing Types/Tags
- Fixes for various hooks
- Added usage description
- First release