field-advanced-link.php
3 months ago
field-button-group.php
1 week ago
field-button.php
7 months ago
field-checkbox.php
3 months ago
field-clone.php
2 years ago
field-code-editor.php
3 months ago
field-column.php
3 years ago
field-dynamic-render.php
3 years ago
field-file.php
3 months ago
field-flexible-content-actions-title.php
3 months ago
field-flexible-content-actions-toggle.php
3 months ago
field-flexible-content-actions.php
3 months ago
field-flexible-content-async.php
4 months ago
field-flexible-content-compatibility.php
3 months ago
field-flexible-content-controls.php
9 months ago
field-flexible-content-hide.php
3 months ago
field-flexible-content-hooks.php
9 months ago
field-flexible-content-modal-edit.php
9 months ago
field-flexible-content-modal-select.php
3 months ago
field-flexible-content-modal-settings.php
3 months ago
field-flexible-content-popup.php
3 months ago
field-flexible-content-preview.php
3 months ago
field-flexible-content-state.php
9 months ago
field-flexible-content-thumbnail.php
9 months ago
field-flexible-content-wysiwyg.php
9 months ago
field-flexible-content.php
3 months ago
field-forms.php
3 months ago
field-gallery.php
3 months ago
field-google-map.php
3 months ago
field-group.php
3 months ago
field-hidden.php
3 years ago
field-image.php
3 months ago
field-post-object.php
3 months ago
field-post-statuses.php
3 months ago
field-post-types.php
3 months ago
field-radio.php
3 months ago
field-recaptcha.php
3 months ago
field-relationship.php
3 months ago
field-repeater.php
3 months ago
field-select.php
3 months ago
field-slug.php
1 year ago
field-taxonomies.php
3 months ago
field-taxonomy-terms.php
3 months ago
field-taxonomy.php
3 months ago
field-textarea.php
3 months ago
field-user-roles.php
3 months ago
field-user.php
3 months ago
field-wysiwyg.php
3 months ago
field-relationship.php
122 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_field_relationship')): |
| 8 | |
| 9 | class acfe_field_relationship extends acfe_field_extend{ |
| 10 | |
| 11 | /** |
| 12 | * initialize |
| 13 | */ |
| 14 | function initialize(){ |
| 15 | |
| 16 | $this->name = 'relationship'; |
| 17 | |
| 18 | } |
| 19 | |
| 20 | |
| 21 | /** |
| 22 | * format_front_value |
| 23 | * |
| 24 | * @param $formatted |
| 25 | * @param $unformatted |
| 26 | * @param $post_id |
| 27 | * @param $field |
| 28 | * @param $form |
| 29 | * |
| 30 | * @return string |
| 31 | */ |
| 32 | function format_front_value($formatted, $unformatted, $post_id, $field, $form){ |
| 33 | |
| 34 | // vars |
| 35 | $value = acfe_as_array($unformatted); |
| 36 | $array = array(); |
| 37 | |
| 38 | // loop values |
| 39 | foreach($value as $p_id){ |
| 40 | |
| 41 | // get post |
| 42 | $post = get_post($p_id); |
| 43 | |
| 44 | // validate |
| 45 | if($post && !is_wp_error($post)){ |
| 46 | $array[] = get_the_title($post->ID); |
| 47 | } |
| 48 | |
| 49 | } |
| 50 | |
| 51 | // merge |
| 52 | return implode(', ', $array); |
| 53 | |
| 54 | } |
| 55 | |
| 56 | |
| 57 | /** |
| 58 | * validate_front_value |
| 59 | * |
| 60 | * @param $valid |
| 61 | * @param $value |
| 62 | * @param $field |
| 63 | * @param $input |
| 64 | * @param $form |
| 65 | * |
| 66 | * @return false |
| 67 | */ |
| 68 | function validate_front_value($valid, $value, $field, $input, $form){ |
| 69 | |
| 70 | // bail early |
| 71 | if(!$this->pre_validate_front_value($valid, $value, $field, $form)){ |
| 72 | return $valid; |
| 73 | } |
| 74 | |
| 75 | // custom value allowed |
| 76 | if(!empty($field['acfe_add_post'])){ |
| 77 | return $valid; |
| 78 | } |
| 79 | |
| 80 | // cast array |
| 81 | $value = acfe_as_array($value); |
| 82 | |
| 83 | // loop values |
| 84 | foreach($value as $v){ |
| 85 | |
| 86 | // get post |
| 87 | $post = get_post($v); |
| 88 | |
| 89 | // check post exists |
| 90 | if(!$post || is_wp_error($post)){ |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | // check query method exists |
| 95 | if(method_exists($this->instance, 'get_ajax_query')){ |
| 96 | |
| 97 | // query relationship ajax query |
| 98 | $query = $this->instance->get_ajax_query(array( |
| 99 | 'field_key' => $field['key'], |
| 100 | 'post_id' => $form['post_id'], |
| 101 | 'include' => $v, |
| 102 | )); |
| 103 | |
| 104 | // return false if no results |
| 105 | if(empty($query)){ |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | } |
| 110 | |
| 111 | } |
| 112 | |
| 113 | // return |
| 114 | return $valid; |
| 115 | |
| 116 | } |
| 117 | |
| 118 | } |
| 119 | |
| 120 | acf_new_instance('acfe_field_relationship'); |
| 121 | |
| 122 | endif; |