Advanced Custom Fields - Version 3.3.3

Version Description

  • [Upgrade] Database Upgrade is required to modify the taxonomy filtering data for fields. This allows for performance boosts throughout ACF.
  • [Improved] relationship field: Improve querying posts / results and use AJAX powered search to increase performance on large-scale websites
  • [Improved] post object field: Improve querying posts / results
Download this release

Release Info

Developer elliotcondon
Plugin Icon 128x128 Advanced Custom Fields
Version 3.3.3
Comparing to
See all releases

Code changes from version 3.3.2 to 3.3.3

acf.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Advanced Custom Fields
4
  Plugin URI: http://www.advancedcustomfields.com/
5
  Description: Fully customise WordPress edit screens with powerful fields. Boasting a professional interface and a powerfull API, it’s a must have for any web developer working with WordPress. Field types include: Wysiwyg, text, textarea, image, file, select, checkbox, page link, post object, date picker, color picker, repeater, flexible content, gallery and more!
6
- Version: 3.3.2
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
@@ -47,8 +47,8 @@ class Acf
47
  // vars
48
  $this->path = plugin_dir_path(__FILE__);
49
  $this->dir = plugins_url('',__FILE__);
50
- $this->version = '3.3.2';
51
- $this->upgrade_version = '3.2.5'; // this is the latest version which requires an upgrade
52
  $this->cache = array(); // basic array cache to hold data throughout the page load
53
 
54
 
@@ -1551,7 +1551,7 @@ class Acf
1551
  {
1552
  foreach($terms as $term)
1553
  {
1554
- $choices[$post_type_object->label . ': ' . $taxonomy][$term->term_id] = $term->name;
1555
  }
1556
  }
1557
  }
@@ -1563,51 +1563,6 @@ class Acf
1563
  }
1564
 
1565
 
1566
- function in_taxonomy($post, $ids)
1567
- {
1568
- $terms = array();
1569
-
1570
- $taxonomies = get_object_taxonomies($post->post_type);
1571
- if($taxonomies)
1572
- {
1573
- foreach($taxonomies as $tax)
1574
- {
1575
- $all_terms = get_the_terms($post->ID, $tax);
1576
- if($all_terms)
1577
- {
1578
- foreach($all_terms as $all_term)
1579
- {
1580
- $terms[] = $all_term->term_id;
1581
- }
1582
- }
1583
- }
1584
- }
1585
-
1586
- if($terms)
1587
- {
1588
- if(is_array($ids))
1589
- {
1590
- foreach($ids as $id)
1591
- {
1592
- if(in_array($id, $terms))
1593
- {
1594
- return true;
1595
- }
1596
- }
1597
- }
1598
- else
1599
- {
1600
- if(in_array($ids, $terms))
1601
- {
1602
- return true;
1603
- }
1604
- }
1605
- }
1606
-
1607
- return false;
1608
-
1609
- }
1610
-
1611
 
1612
  /*
1613
  * get_all_image_sizes
3
  Plugin Name: Advanced Custom Fields
4
  Plugin URI: http://www.advancedcustomfields.com/
5
  Description: Fully customise WordPress edit screens with powerful fields. Boasting a professional interface and a powerfull API, it’s a must have for any web developer working with WordPress. Field types include: Wysiwyg, text, textarea, image, file, select, checkbox, page link, post object, date picker, color picker, repeater, flexible content, gallery and more!
6
+ Version: 3.3.3
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
47
  // vars
48
  $this->path = plugin_dir_path(__FILE__);
49
  $this->dir = plugins_url('',__FILE__);
50
+ $this->version = '3.3.3';
51
+ $this->upgrade_version = '3.3.3'; // this is the latest version which requires an upgrade
52
  $this->cache = array(); // basic array cache to hold data throughout the page load
53
 
54
 
1551
  {
1552
  foreach($terms as $term)
1553
  {
1554
+ $choices[$post_type_object->label . ': ' . $taxonomy][$taxonomy . ':' . $term->term_id] = $term->name;
1555
  }
1556
  }
1557
  }
1563
  }
1564
 
1565
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1566
 
1567
  /*
1568
  * get_all_image_sizes
core/controllers/upgrade.php CHANGED
@@ -67,9 +67,13 @@ class acf_upgrade
67
  {
68
  if( $version < $this->parent->upgrade_version )
69
  {
70
- $this->parent->admin_message('<p>' . __("Advanced Custom Fields",'acf') . 'v' . $this->parent->version . ' ' . __("requires a database upgrade",'acf') .' (<a class="thickbox" href="' . admin_url() . 'plugin-install.php?tab=plugin-information&plugin=advanced-custom-fields&section=changelog&TB_iframe=true&width=640&height=559">' . __("why?",'acf') .'</a>). ' . __("Please",'acf') .' <a href="http://codex.wordpress.org/Backing_Up_Your_Database">' . __("backup your database",'acf') .'</a>, '. __("then click",'acf') . ' <a href="' . admin_url() . 'edit.php?post_type=acf&page=acf-upgrade" class="button">' . __("Upgrade Database",'acf') . '</a></p>');
71
 
72
  }
 
 
 
 
73
  }
74
  else
75
  {
@@ -104,6 +108,10 @@ class acf_upgrade
104
  {
105
  $next = '3.2.5';
106
  }
 
 
 
 
107
 
108
  ?>
109
  <script type="text/javascript">
@@ -624,10 +632,108 @@ class acf_upgrade
624
  $return = array(
625
  'status' => true,
626
  'message' => $message,
627
- 'next' => false,
628
  );
629
 
630
  break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
631
  }
632
 
633
  // return json
67
  {
68
  if( $version < $this->parent->upgrade_version )
69
  {
70
+ $this->parent->admin_message('<p>' . __("Advanced Custom Fields",'acf') . ' v' . $this->parent->version . ' ' . __("requires a database upgrade",'acf') .' (<a class="thickbox" href="' . admin_url() . 'plugin-install.php?tab=plugin-information&plugin=advanced-custom-fields&section=changelog&TB_iframe=true&width=640&height=559">' . __("why?",'acf') .'</a>). ' . __("Please",'acf') .' <a href="http://codex.wordpress.org/Backing_Up_Your_Database">' . __("backup your database",'acf') .'</a>, '. __("then click",'acf') . ' <a href="' . admin_url() . 'edit.php?post_type=acf&page=acf-upgrade" class="button">' . __("Upgrade Database",'acf') . '</a></p>');
71
 
72
  }
73
+ elseif( $version < $this->parent->version)
74
+ {
75
+ update_option('acf_version', $this->parent->version );
76
+ }
77
  }
78
  else
79
  {
108
  {
109
  $next = '3.2.5';
110
  }
111
+ elseif( $version < '3.3.3' )
112
+ {
113
+ $next = '3.3.3';
114
+ }
115
 
116
  ?>
117
  <script type="text/javascript">
632
  $return = array(
633
  'status' => true,
634
  'message' => $message,
635
+ 'next' => '3.3.3',
636
  );
637
 
638
  break;
639
+
640
+
641
+ /*
642
+ * 3.3.3
643
+ *
644
+ * @description: changed field option: taxonomies filter on relationship / post object and page link fields.
645
+ * @created: 20/07/12
646
+ */
647
+
648
+ case '3.3.3':
649
+
650
+ // vars
651
+ $message = __("Modifying field option 'taxonomy'",'acf') . '...';
652
+ $wp_term_taxonomy = $wpdb->prefix.'term_taxonomy';
653
+ $term_taxonomies = array();
654
+
655
+ $rows = $wpdb->get_results("SELECT * FROM $wp_term_taxonomy", ARRAY_A);
656
+
657
+ if($rows)
658
+ {
659
+ foreach($rows as $row)
660
+ {
661
+ $term_taxonomies[ $row['term_id'] ] = $row['taxonomy'] . ":" . $row['term_id'];
662
+ }
663
+ }
664
+
665
+
666
+ // get acf's
667
+ $acfs = get_pages(array(
668
+ 'numberposts' => -1,
669
+ 'post_type' => 'acf',
670
+ 'sort_column' => 'menu_order',
671
+ 'order' => 'ASC',
672
+ ));
673
+
674
+ // populate acfs
675
+ if($acfs)
676
+ {
677
+ foreach($acfs as $acf)
678
+ {
679
+ $fields = $this->parent->get_acf_fields($acf->ID);
680
+
681
+ if( $fields )
682
+ {
683
+ foreach( $fields as $field )
684
+ {
685
+
686
+ // only edit the option: taxonomy
687
+ if( !isset($field['taxonomy']) )
688
+ {
689
+ continue;
690
+ }
691
+
692
+
693
+ if( $field['taxonomy'] )
694
+ {
695
+ foreach( $field['taxonomy'] as $k => $v )
696
+ {
697
+
698
+ // could be "all"
699
+ if( !is_numeric($v) )
700
+ {
701
+ continue;
702
+ }
703
+
704
+ $field['taxonomy'][ $k ] = $term_taxonomies[ $v ];
705
+
706
+
707
+ }
708
+ // foreach( $field['taxonomy'] as $k => $v )
709
+ }
710
+ // if( $field['taxonomy'] )
711
+
712
+
713
+ $this->parent->update_field( $acf->ID, $field);
714
+
715
+ }
716
+ // foreach( $fields as $field )
717
+ }
718
+ // if( $fields )
719
+ }
720
+ // foreach($acfs as $acf)
721
+ }
722
+ // if($acfs)
723
+
724
+
725
+ // update version
726
+ update_option('acf_version','3.3.3');
727
+
728
+ $return = array(
729
+ 'status' => true,
730
+ 'message' => $message,
731
+ 'next' => false,
732
+ );
733
+
734
+ break;
735
+
736
+
737
  }
738
 
739
  // return json
core/fields/post_object.php CHANGED
@@ -36,153 +36,151 @@ class acf_Post_object extends acf_Field
36
  function create_field($field)
37
  {
38
  // vars
39
- $field['multiple'] = isset($field['multiple']) ? $field['multiple'] : false;
40
- $field['post_type'] = isset($field['post_type']) ? $field['post_type'] : false;
41
- //$field['meta_key'] = isset($field['meta_key']) ? $field['meta_key'] : false;
42
- //$field['meta_value'] = isset($field['meta_value']) ? $field['meta_value'] : false;
 
 
 
 
43
 
 
 
 
 
 
 
44
 
45
- if(!$field['post_type'] || !is_array($field['post_type']) || $field['post_type'][0] == "")
46
- {
47
- $field['post_type'] = get_post_types(array('public' => true));
48
- }
49
-
50
- // multiple select
51
- $multiple = '';
52
- if($field['multiple'] == '1')
53
- {
54
- $multiple = ' multiple="multiple" size="5" ';
55
- $field['name'] .= '[]';
56
- }
57
 
58
- // html
59
- echo '<select id="' . $field['name'] . '" class="' . $field['class'] . '" name="' . $field['name'] . '" ' . $multiple . ' >';
60
 
61
- // null
62
- if($field['allow_null'] == '1')
63
  {
64
- echo '<option value="null"> - ' . __("Select",'acf') . ' - </option>';
65
  }
 
66
 
67
-
68
- foreach($field['post_type'] as $post_type)
69
  {
70
- // get posts
71
- $posts = false;
 
72
 
73
- if(is_post_type_hierarchical($post_type))
74
- {
75
- // get pages
76
- $posts = get_pages(array(
77
- 'numberposts' => -1,
78
- 'post_type' => $post_type,
79
- 'sort_column' => 'menu_order',
80
- 'order' => 'ASC',
81
- 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
82
- 'suppress_filters' => false,
83
- //'meta_key' => $field['meta_key'],
84
- //'meta_value' => $field['meta_value'],
85
- ));
86
- }
87
- else
88
  {
89
- // get posts
90
- $posts = get_posts(array(
91
- 'numberposts' => -1,
92
- 'post_type' => $post_type,
93
- 'orderby' => 'title',
94
- 'order' => 'ASC',
95
- 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
96
- 'suppress_filters' => false,
97
- //'meta_key' => $field['meta_key'],
98
- //'meta_value' => $field['meta_value'],
99
- ));
 
 
 
 
 
100
  }
101
-
102
- // filter by taxonomy
103
- if(in_array('all', $field['taxonomy']))
 
104
  {
105
- // leave all posts
 
 
 
 
106
  }
107
- else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  {
109
- if($posts)
110
- {
111
- foreach($posts as $k => $post)
112
- {
113
- if(!$this->parent->in_taxonomy($post, $field['taxonomy']))
114
- {
115
- unset($posts[$k]);
116
- }
117
- }
118
- }
119
  }
120
-
121
-
122
- // if posts, make a group for them
 
 
123
  if($posts)
124
  {
125
- $post_type_object = get_post_type_object($post_type);
126
- $post_type_name = $post_type_object->labels->name;
127
-
128
- echo '<optgroup label="'.$post_type_name.'">';
129
-
130
- foreach($posts as $post)
131
  {
132
- $key = $post->ID;
133
 
134
- $value = '';
135
- $ancestors = get_ancestors($post->ID, $post_type);
 
 
 
136
  if($ancestors)
137
  {
138
  foreach($ancestors as $a)
139
  {
140
- $value .= '– ';
141
  }
142
  }
143
- $value .= get_the_title($post->ID);
 
144
 
145
  // status
146
  if($post->post_status == "private" || $post->post_status == "draft")
147
  {
148
- $value .= " ($post->post_status)";
149
  }
150
 
151
 
152
- $selected = '';
153
-
154
-
155
- if(is_array($field['value']))
156
  {
157
- // 2. If the value is an array (multiple select), loop through values and check if it is selected
158
- if(in_array($key, $field['value']))
159
- {
160
- $selected = 'selected="selected"';
161
- }
162
  }
163
  else
164
  {
165
- // 3. this is not a multiple select, just check normaly
166
- if($key == $field['value'])
167
- {
168
- $selected = 'selected="selected"';
169
- }
170
- }
171
 
172
-
173
- echo '<option value="'.$key.'" '.$selected.'>'.$value.'</option>';
 
174
 
175
 
176
- }
177
-
178
- echo '</optgroup>';
179
-
180
- }// endif
181
-
182
- }// endforeach
 
 
 
 
183
 
184
-
185
- echo '</select>';
186
  }
187
 
188
 
@@ -199,12 +197,15 @@ class acf_Post_object extends acf_Field
199
  function create_options($key, $field)
200
  {
201
  // defaults
202
- $field['post_type'] = isset($field['post_type']) ? $field['post_type'] : '';
203
- $field['multiple'] = isset($field['multiple']) ? $field['multiple'] : '0';
204
- $field['allow_null'] = isset($field['allow_null']) ? $field['allow_null'] : '0';
205
- $field['taxonomy'] = isset($field['taxonomy']) ? $field['taxonomy'] : array('all');
206
- //$field['meta_key'] = isset($field['meta_key']) ? $field['meta_key'] : '';
207
- //$field['meta_value'] = isset($field['meta_value']) ? $field['meta_value'] : '';
 
 
 
208
  ?>
209
  <tr class="field_option field_option_<?php echo $this->name; ?>">
210
  <td class="label">
@@ -212,17 +213,23 @@ class acf_Post_object extends acf_Field
212
  </td>
213
  <td>
214
  <?php
215
- $post_types = array('' => __("All",'acf'));
216
 
217
- foreach (get_post_types(array('public' => true)) as $post_type ) {
218
- $post_types[$post_type] = $post_type;
 
 
 
 
 
 
 
219
  }
220
 
221
  $this->parent->create_field(array(
222
  'type' => 'select',
223
  'name' => 'fields['.$key.'][post_type]',
224
  'value' => $field['post_type'],
225
- 'choices' => $post_types,
226
  'multiple' => '1',
227
  ));
228
  ?>
@@ -251,33 +258,6 @@ class acf_Post_object extends acf_Field
251
  ?>
252
  </td>
253
  </tr>
254
- <?php /*<tr class="field_option field_option_<?php echo $this->name; ?>">
255
- <td class="label">
256
- <label><?php _e("Filter Posts",'acf'); ?></label>
257
- <p class="description"><?php _e("Where meta_key == meta_value",'acf'); ?></p>
258
- </td>
259
- <td>
260
- <div style="width:45%; float:left">
261
- <?php
262
- $this->parent->create_field(array(
263
- 'type' => 'text',
264
- 'name' => 'fields['.$key.'][meta_key]',
265
- 'value' => $field['meta_key'],
266
- ));
267
- ?>
268
- </div>
269
- <div style="width:10%; float:left; text-align:center; padding:5px 0 0;">is equal to</div>
270
- <div style="width:45%; float:left">
271
- <?php
272
- $this->parent->create_field(array(
273
- 'type' => 'text',
274
- 'name' => 'fields['.$key.'][meta_value]',
275
- 'value' => $field['meta_value'],
276
- ));
277
- ?>
278
- </div>
279
- </td>
280
- </tr>*/ ?>
281
  <tr class="field_option field_option_<?php echo $this->name; ?>">
282
  <td class="label">
283
  <label><?php _e("Allow Null?",'acf'); ?></label>
@@ -334,28 +314,55 @@ class acf_Post_object extends acf_Field
334
  // get value
335
  $value = parent::get_value($post_id, $field);
336
 
337
- if(!$value)
 
 
338
  {
339
  return false;
340
  }
341
 
342
- if($value == 'null')
 
 
343
  {
344
  return false;
345
  }
346
 
347
- if(is_array($value))
 
 
348
  {
349
- foreach($value as $k => $v)
 
 
 
 
 
 
 
 
 
 
350
  {
351
- $value[$k] = get_post($v);
 
352
  }
 
 
 
 
 
 
 
 
353
  }
354
  else
355
  {
356
  $value = get_post($value);
357
  }
358
 
 
 
359
  return $value;
360
  }
361
 
36
  function create_field($field)
37
  {
38
  // vars
39
+ $args = array(
40
+ 'numberposts' => -1,
41
+ 'post_type' => null,
42
+ 'orderby' => 'title',
43
+ 'order' => 'ASC',
44
+ 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
45
+ 'suppress_filters' => false,
46
+ );
47
 
48
+ $defaults = array(
49
+ 'multiple' => '0',
50
+ 'post_type' => false,
51
+ 'taxonomy' => array('all'),
52
+ 'allow_null' => '0',
53
+ );
54
 
55
+
56
+ $field = array_merge($defaults, $field);
 
 
 
 
 
 
 
 
 
 
57
 
 
 
58
 
59
+ // load all post types by default
60
+ if( !$field['post_type'] || !is_array($field['post_type']) || $field['post_type'][0] == "" )
61
  {
62
+ $field['post_type'] = get_post_types( array('public' => true) );
63
  }
64
+
65
 
66
+ // create tax queries
67
+ if( ! in_array('all', $field['taxonomy']) )
68
  {
69
+ // vars
70
+ $taxonomies = array();
71
+ $args['tax_query'] = array();
72
 
73
+ foreach( $field['taxonomy'] as $v )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  {
75
+
76
+ // find term (find taxonomy!)
77
+ // $term = array( 0 => $taxonomy, 1 => $term_id )
78
+ $term = explode(':', $v);
79
+
80
+
81
+ // validate
82
+ if( !is_array($term) || !isset($term[1]) )
83
+ {
84
+ continue;
85
+ }
86
+
87
+
88
+ // add to tax array
89
+ $taxonomies[ $term[0] ][] = $term[1];
90
+
91
  }
92
+
93
+
94
+ // now create the tax queries
95
+ foreach( $taxonomies as $k => $v )
96
  {
97
+ $args['tax_query'][] = array(
98
+ 'taxonomy' => $k,
99
+ 'field' => 'id',
100
+ 'terms' => $v,
101
+ );
102
  }
103
+ }
104
+
105
+
106
+ // Change Field into a select
107
+ $field['type'] = 'select';
108
+ $field['choices'] = array();
109
+ $field['optgroup'] = false;
110
+
111
+
112
+ foreach( $field['post_type'] as $post_type )
113
+ {
114
+ // set post_type
115
+ $args['post_type'] = $post_type;
116
+
117
+
118
+ // set order
119
+ if( is_post_type_hierarchical($post_type) )
120
  {
121
+ $args['orderby'] = 'menu_order';
 
 
 
 
 
 
 
 
 
122
  }
123
+
124
+
125
+ // get posts
126
+ $posts = get_posts( $args );
127
+
128
  if($posts)
129
  {
130
+ foreach( $posts as $post )
 
 
 
 
 
131
  {
132
+ // find the post type title
133
 
134
+
135
+
136
+ // find title. Could use get_the_title, but that uses get_post(), so I think this uses less Memory
137
+ $title = '';
138
+ $ancestors = get_ancestors( $post->ID, $post->post_type );
139
  if($ancestors)
140
  {
141
  foreach($ancestors as $a)
142
  {
143
+ $title .= '–';
144
  }
145
  }
146
+ $title .= ' ' . apply_filters( 'the_title', $post->post_title, $post->ID );
147
+
148
 
149
  // status
150
  if($post->post_status == "private" || $post->post_status == "draft")
151
  {
152
+ $title .= " ($post->post_status)";
153
  }
154
 
155
 
156
+ // add to choices
157
+ if( count($field['post_type']) == 1 )
 
 
158
  {
159
+ $field['choices'][ $post->ID ] = $title;
 
 
 
 
160
  }
161
  else
162
  {
163
+ // group by post type
164
+ $post_type_object = get_post_type_object( $post->post_type );
165
+ $post_type_name = $post_type_object->labels->name;
 
 
 
166
 
167
+ $field['choices'][ $post_type_name ][ $post->ID ] = $title;
168
+ $field['optgroup'] = true;
169
+ }
170
 
171
 
172
+ }
173
+ // foreach( $posts as $post )
174
+ }
175
+ // if($posts)
176
+ }
177
+ // foreach( $field['post_type'] as $post_type )
178
+
179
+
180
+ // create field
181
+ $this->parent->create_field( $field );
182
+
183
 
 
 
184
  }
185
 
186
 
197
  function create_options($key, $field)
198
  {
199
  // defaults
200
+ $defaults = array(
201
+ 'post_type' => '',
202
+ 'multiple' => '0',
203
+ 'allow_null' => '0',
204
+ 'taxonomy' => array('all'),
205
+ );
206
+
207
+ $field = array_merge($defaults, $field);
208
+
209
  ?>
210
  <tr class="field_option field_option_<?php echo $this->name; ?>">
211
  <td class="label">
213
  </td>
214
  <td>
215
  <?php
 
216
 
217
+ $choices = array(
218
+ '' => __("All",'acf')
219
+ );
220
+
221
+ $post_types = get_post_types( array('public' => true) );
222
+
223
+ foreach( $post_types as $post_type )
224
+ {
225
+ $choices[$post_type] = $post_type;
226
  }
227
 
228
  $this->parent->create_field(array(
229
  'type' => 'select',
230
  'name' => 'fields['.$key.'][post_type]',
231
  'value' => $field['post_type'],
232
+ 'choices' => $choices,
233
  'multiple' => '1',
234
  ));
235
  ?>
258
  ?>
259
  </td>
260
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  <tr class="field_option field_option_<?php echo $this->name; ?>">
262
  <td class="label">
263
  <label><?php _e("Allow Null?",'acf'); ?></label>
314
  // get value
315
  $value = parent::get_value($post_id, $field);
316
 
317
+
318
+ // no value?
319
+ if( !$value )
320
  {
321
  return false;
322
  }
323
 
324
+
325
+ // null?
326
+ if( $value == 'null' )
327
  {
328
  return false;
329
  }
330
 
331
+
332
+ // multiple / single
333
+ if( is_array($value) )
334
  {
335
+ // find posts (DISTINCT POSTS)
336
+ $posts = get_posts(array(
337
+ 'numberposts' => -1,
338
+ 'post__in' => $value,
339
+ 'post_type' => get_post_types( array('public' => true) ),
340
+ 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
341
+ ));
342
+
343
+
344
+ $ordered_posts = array();
345
+ foreach( $posts as $post )
346
  {
347
+ // create array to hold value data
348
+ $ordered_posts[ $post->ID ] = $post;
349
  }
350
+
351
+
352
+ // override value array with attachments
353
+ foreach( $value as $k => $v)
354
+ {
355
+ $value[ $k ] = $ordered_posts[ $v ];
356
+ }
357
+
358
  }
359
  else
360
  {
361
  $value = get_post($value);
362
  }
363
 
364
+
365
+ // return the value
366
  return $value;
367
  }
368
 
core/fields/relationship.php CHANGED
@@ -20,9 +20,137 @@ class acf_Relationship extends acf_Field
20
  $this->name = 'relationship';
21
  $this->title = __("Relationship",'acf');
22
 
 
23
  }
24
 
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  /*--------------------------------------------------------------------------------------
27
  *
28
  * admin_print_scripts / admin_print_styles
@@ -57,166 +185,103 @@ class acf_Relationship extends acf_Field
57
 
58
  function create_field($field)
59
  {
60
-
61
- $field['max'] = isset($field['max']) ? $field['max'] : '-1';
62
- $field['post_type'] = isset($field['post_type']) ? $field['post_type'] : false;
63
- $field['taxonomy'] = isset($field['taxonomy']) ? $field['taxonomy'] : array('all');
64
- //$field['meta_key'] = isset($field['meta_key']) ? $field['meta_key'] : false;
65
- //$field['meta_value'] = isset($field['meta_value']) ? $field['meta_value'] : false;
66
-
67
- if(!$field['post_type'] || !is_array($field['post_type']) || $field['post_type'][0] == "")
68
- {
69
- $field['post_type'] = get_post_types(array('public' => true));
70
- }
71
 
72
- // attachment doesn't work if it is the only item in an array???
73
- if(is_array($field['post_type']) && count($field['post_type']) == 1)
74
- {
75
- $field['post_type'] = $field['post_type'][0];
76
- }
77
-
78
- $posts = get_posts(array(
79
- 'numberposts' => -1,
80
- 'post_type' => $field['post_type'],
81
- 'orderby' => 'title',
82
- 'order' => 'ASC',
83
- 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
84
- 'suppress_filters' => false,
85
- //'meta_key' => $field['meta_key'],
86
- //'meta_value' => $field['meta_value'],
87
- ));
88
 
89
- // filter by taxonomy
90
- if(in_array('all', $field['taxonomy']))
91
- {
92
- // leave all posts
93
- }
94
- else
95
- {
96
- if($posts)
97
- {
98
- foreach($posts as $k => $post)
99
- {
100
- if(!$this->parent->in_taxonomy($post, $field['taxonomy']))
101
- {
102
- unset($posts[$k]);
103
- }
104
- }
105
- }
106
- }
107
 
108
- $values_array = array();
109
- if($field['value'] != "")
 
 
 
 
110
  {
111
- $temp_array = explode(',', $field['value']);
112
- foreach($temp_array as $p)
113
- {
114
- // if the post doesn't exist, continue
115
- if(!get_the_title($p)) continue;
116
-
117
- $values_array[] = $p;
118
- }
119
  }
120
 
121
 
122
-
 
 
 
 
123
 
124
 
125
  ?>
126
- <div class="acf_relationship" data-max="<?php echo $field['max']; ?>">
127
-
128
- <input type="hidden" name="<?php echo $field['name']; ?>" value="<?php echo implode(',', $values_array); ?>" />
129
-
130
- <div class="relationship_left">
131
- <table class="widefat">
132
- <thead>
133
- <tr>
134
- <th>
135
- <label class="relationship_label" for="relationship_<?php echo $field['name']; ?>"><?php _e("Search",'acf'); ?>...</label>
136
- <input class="relationship_search" type="text" id="relationship_<?php echo $field['name']; ?>" />
137
- <div class="clear_relationship_search"></div>
138
- </th>
139
- </tr>
140
- </thead>
141
- </table>
142
- <div class="relationship_list">
143
- <?php
144
- if($posts)
145
- {
146
- foreach($posts as $post)
147
- {
148
- if(!get_the_title($post->ID)) continue;
149
-
150
- $class = in_array($post->ID, $values_array) ? 'hide' : '';
151
-
152
- $title = get_the_title($post->ID);
153
- // status
154
- if($post->post_status == "private" || $post->post_status == "draft")
155
- {
156
- $title .= " ($post->post_status)";
157
- }
158
-
159
- echo '<a href="javascript:;" class="' . $class . '" data-post_id="' . $post->ID . '">' . $title . '<span class="add"></span></a>';
160
- }
161
- }
162
- ?>
163
- </div>
164
- </div>
165
-
166
- <div class="relationship_right">
167
- <div class="relationship_list">
168
- <?php
169
- $temp_posts = array();
170
 
171
- if($posts)
 
 
 
 
 
172
  {
173
- foreach($posts as $post)
174
- {
175
- $temp_posts[$post->ID] = $post;
176
- }
177
  }
178
 
179
- if($temp_posts)
180
- {
181
- foreach($values_array as $value)
182
- {
183
- if(!isset($temp_posts[$value]))
184
- {
185
- continue;
186
- }
187
-
188
- $post = $temp_posts[$value];
189
-
190
- $title = get_the_title($post->ID);
191
- // status
192
- if($post->post_status == "private" || $post->post_status == "draft")
193
- {
194
- $title .= " ($post->post_status)";
195
- }
196
-
197
- echo '<a href="javascript:;" class="" data-post_id="' . $temp_posts[$value]->ID . '">' . $title . '<span class="remove"></span></a>';
198
- unset($temp_posts[$value]);
199
- }
200
-
201
- foreach($temp_posts as $id => $post)
202
- {
203
- $title = get_the_title($post->ID);
204
- // status
205
- if($post->post_status == "private" || $post->post_status == "draft")
206
- {
207
- $title .= " ($post->post_status)";
208
- }
209
-
210
- echo '<a href="javascript:;" class="hide" data-post_id="' . $post->ID . '">' . $title . '<span class="remove"></span></a>';
211
- }
212
- }
213
-
214
- ?>
215
- </div>
216
- </div>
217
-
218
 
219
- </div>
 
 
 
 
 
220
  <?php
221
 
222
 
@@ -234,13 +299,16 @@ class acf_Relationship extends acf_Field
234
  *-------------------------------------------------------------------------------------*/
235
 
236
  function create_options($key, $field)
237
- {
238
- // defaults
239
- $field['post_type'] = isset($field['post_type']) ? $field['post_type'] : '';
240
- $field['max'] = isset($field['max']) ? $field['max'] : '-1';
241
- $field['taxonomy'] = isset($field['taxonomy']) ? $field['taxonomy'] : array('all');
242
- //$field['meta_key'] = isset($field['meta_key']) ? $field['meta_key'] : '';
243
- //$field['meta_value'] = isset($field['meta_value']) ? $field['meta_value'] : '';
 
 
 
244
  ?>
245
  <tr class="field_option field_option_<?php echo $this->name; ?>">
246
  <td class="label">
@@ -248,49 +316,29 @@ class acf_Relationship extends acf_Field
248
  </td>
249
  <td>
250
  <?php
251
- $post_types = array('' => __("All",'acf'));
252
 
253
- foreach (get_post_types(array('public' => true)) as $post_type ) {
254
- $post_types[$post_type] = $post_type;
 
 
 
 
 
 
 
255
  }
256
 
257
  $this->parent->create_field(array(
258
  'type' => 'select',
259
  'name' => 'fields['.$key.'][post_type]',
260
  'value' => $field['post_type'],
261
- 'choices' => $post_types,
262
  'multiple' => '1',
263
  ));
 
264
  ?>
265
  </td>
266
  </tr>
267
- <?php /*<tr class="field_option field_option_<?php echo $this->name; ?>">
268
- <td class="label">
269
- <label><?php _e("Filter Posts",'acf'); ?></label>
270
- <p class="description"><?php _e("Where meta_key == meta_value",'acf'); ?></p>
271
- </td>
272
- <td>
273
- <div style="width:45%; float:left">
274
- <?php
275
- $this->parent->create_field(array(
276
- 'type' => 'text',
277
- 'name' => 'fields['.$key.'][meta_key]',
278
- 'value' => $field['meta_key'],
279
- ));
280
- ?>
281
- </div>
282
- <div style="width:10%; float:left; text-align:center; padding:5px 0 0;">is equal to</div>
283
- <div style="width:45%; float:left">
284
- <?php
285
- $this->parent->create_field(array(
286
- 'type' => 'text',
287
- 'name' => 'fields['.$key.'][meta_value]',
288
- 'value' => $field['meta_value'],
289
- ));
290
- ?>
291
- </div>
292
- </td>
293
- </tr>*/ ?>
294
  <tr class="field_option field_option_<?php echo $this->name; ?>">
295
  <td class="label">
296
  <label><?php _e("Filter from Taxonomy",'acf'); ?></label>
@@ -317,7 +365,6 @@ class acf_Relationship extends acf_Field
317
  <tr class="field_option field_option_<?php echo $this->name; ?>">
318
  <td class="label">
319
  <label><?php _e("Maximum posts",'acf'); ?></label>
320
- <p class="description"><?php _e("Set to -1 for infinite",'acf'); ?></p>
321
  </td>
322
  <td>
323
  <?php
@@ -329,54 +376,72 @@ class acf_Relationship extends acf_Field
329
  ?>
330
  </td>
331
  </tr>
332
-
333
-
334
-
335
  <?php
336
  }
337
 
338
 
339
  /*--------------------------------------------------------------------------------------
340
  *
341
- * get_value_for_api
342
  *
343
  * @author Elliot Condon
344
- * @since 3.0.0
345
  *
346
  *-------------------------------------------------------------------------------------*/
347
 
348
- function get_value_for_api($post_id, $field)
349
  {
350
- // vars
351
  $value = parent::get_value($post_id, $field);
352
- $return = false;
353
 
354
- if(!$value || $value == "")
 
 
355
  {
356
- return $return;
357
  }
358
 
359
- $value = explode(',', $value);
360
 
361
- if(is_array($value))
 
362
  {
363
- $return = array();
364
- foreach($value as $v)
365
- {
366
- $p = get_post($v);
367
-
368
- if( $p && in_array( $p->post_status, array('publish', 'private', 'draft', 'inherit')) )
369
- {
370
- $return[] = $p;
371
- }
372
- }
373
  }
374
- else
 
 
 
375
  {
376
- $return = array(get_post($value));
377
  }
378
 
379
- return $return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  }
381
 
382
 
20
  $this->name = 'relationship';
21
  $this->title = __("Relationship",'acf');
22
 
23
+ add_action('wp_ajax_acf_get_relationship_results', array($this, 'acf_get_relationship_results'));
24
  }
25
 
26
 
27
+ /*--------------------------------------------------------------------------------------
28
+ *
29
+ * acf_get_relationship_results
30
+ *
31
+ * @author Elliot Condon
32
+ * @description: Generates HTML for Left column relationship results
33
+ * @created: 5/07/12
34
+ *
35
+ *-------------------------------------------------------------------------------------*/
36
+
37
+ function acf_get_relationship_results()
38
+ {
39
+
40
+ // vars
41
+ $options = array(
42
+ 'post_type' => '',
43
+ 'taxonomy' => 'all',
44
+ 'posts_per_page' => 10,
45
+ 'paged' => 0,
46
+ 'orderby' => 'title',
47
+ 'order' => 'ASC',
48
+ 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
49
+ 'suppress_filters' => false,
50
+ 's' => ''
51
+ );
52
+ $ajax = isset( $_POST['action'] ) ? true : false;
53
+
54
+
55
+ // override options with posted values
56
+ if( $ajax )
57
+ {
58
+ $options = array_merge($options, $_POST);
59
+ }
60
+
61
+
62
+ // convert types
63
+ $options['post_type'] = explode(',', $options['post_type']);
64
+ $options['taxonomy'] = explode(',', $options['taxonomy']);
65
+
66
+
67
+ // load all post types by default
68
+ if( !$options['post_type'] || !is_array($options['post_type']) || $options['post_type'][0] == "" )
69
+ {
70
+ $options['post_type'] = get_post_types( array('public' => true) );
71
+ }
72
+
73
+
74
+ // attachment doesn't work if it is the only item in an array???
75
+ if( is_array($options['post_type']) && count($options['post_type']) == 1 )
76
+ {
77
+ $options['post_type'] = $options['post_type'][0];
78
+ }
79
+
80
+
81
+ // create tax queries
82
+ if( ! in_array('all', $options['taxonomy']) )
83
+ {
84
+ // vars
85
+ $taxonomies = array();
86
+ $options['tax_query'] = array();
87
+
88
+ foreach( $options['taxonomy'] as $v )
89
+ {
90
+
91
+ // find term (find taxonomy!)
92
+ // $term = array( 0 => $taxonomy, 1 => $term_id )
93
+ $term = explode(':', $v);
94
+
95
+
96
+ // validate
97
+ if( !is_array($term) || !isset($term[1]) )
98
+ {
99
+ continue;
100
+ }
101
+
102
+
103
+ // add to tax array
104
+ $taxonomies[ $term[0] ][] = $term[1];
105
+
106
+ }
107
+
108
+
109
+ // now create the tax queries
110
+ foreach( $taxonomies as $k => $v )
111
+ {
112
+ $options['tax_query'][] = array(
113
+ 'taxonomy' => $k,
114
+ 'field' => 'id',
115
+ 'terms' => $v,
116
+ );
117
+ }
118
+ }
119
+
120
+ unset( $options['taxonomy'] );
121
+
122
+
123
+ // load the posts
124
+ $posts = get_posts( $options );
125
+
126
+ if( $posts )
127
+ {
128
+ foreach( $posts as $post )
129
+ {
130
+ // find title. Could use get_the_title, but that uses get_post(), so I think this uses less Memory
131
+ $title = apply_filters( 'the_title', $post->post_title, $post->ID );
132
+
133
+
134
+ // status
135
+ if($post->post_status == "private" || $post->post_status == "draft")
136
+ {
137
+ $title .= " ($post->post_status)";
138
+ }
139
+
140
+ echo '<li><a href="javascript:;" data-post_id="' . $post->ID . '">' . $title . '<span class="add"></span></a></li>';
141
+ }
142
+ }
143
+
144
+
145
+ // die?
146
+ if( $ajax )
147
+ {
148
+ die();
149
+ }
150
+
151
+ }
152
+
153
+
154
  /*--------------------------------------------------------------------------------------
155
  *
156
  * admin_print_scripts / admin_print_styles
185
 
186
  function create_field($field)
187
  {
188
+ // vars
189
+ $defaults = array(
190
+ 'post_type' => '',
191
+ 'max' => -1,
192
+ 'taxonomy' => array('all'),
193
+ );
 
 
 
 
 
194
 
195
+ $field = array_merge($defaults, $field);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
 
198
+ // validate types
199
+ $field['max'] = (int) $field['max'];
200
+
201
+
202
+ // row limit <= 0?
203
+ if( $field['max'] <= 0 )
204
  {
205
+ $field['max'] = 9999;
 
 
 
 
 
 
 
206
  }
207
 
208
 
209
+ // load all post types by default
210
+ if( !$field['post_type'] || !is_array($field['post_type']) || $field['post_type'][0] == "" )
211
+ {
212
+ $field['post_type'] = get_post_types( array('public' => true) );
213
+ }
214
 
215
 
216
  ?>
217
+ <div class="acf_relationship" data-max="<?php echo $field['max']; ?>" data-s="" data-paged="1" data-post_type="<?php echo implode(',', $field['post_type']); ?>" data-taxonomy="<?php echo implode(',', $field['taxonomy']); ?>">
218
+
219
+ <!-- Hidden Blank default value -->
220
+ <input type="hidden" name="<?php echo $field['name']; ?>" value="" />
221
+
222
+ <!-- Template for value -->
223
+ <script type="text/html" class="tmpl-li">
224
+ <li>
225
+ <a href="#" data-post_id="{post_id}">{title}<span class="remove"></span></a>
226
+ <input type="hidden" name="<?php echo $field['name']; ?>[]" value="{post_id}" />
227
+ </li>
228
+ </script>
229
+ <!-- / Template for value -->
230
+
231
+ <!-- Left List -->
232
+ <div class="relationship_left">
233
+ <table class="widefat">
234
+ <thead>
235
+ <tr>
236
+ <th>
237
+ <label class="relationship_label" for="relationship_<?php echo $field['name']; ?>"><?php _e("Search",'acf'); ?>...</label>
238
+ <input class="relationship_search" type="text" id="relationship_<?php echo $field['name']; ?>" />
239
+ <div class="clear_relationship_search"></div>
240
+ </th>
241
+ </tr>
242
+ </thead>
243
+ </table>
244
+ <ul class="bl relationship_list">
245
+ <li class="load-more">
246
+ <div class="acf-loading"></div>
247
+ </li>
248
+ </ul>
249
+ </div>
250
+ <!-- /Left List -->
251
+
252
+ <!-- Right List -->
253
+ <div class="relationship_right">
254
+ <ul class="bl relationship_list">
255
+ <?php
256
+
257
+ if( $field['value'] )
258
+ {
259
+ foreach( $field['value'] as $post )
260
+ {
261
 
262
+ // find title. Could use get_the_title, but that uses get_post(), so I think this uses less Memory
263
+ $title = apply_filters( 'the_title', $post->post_title, $post->ID );
264
+
265
+
266
+ // status
267
+ if($post->post_status == "private" || $post->post_status == "draft")
268
  {
269
+ $title .= " ($post->post_status)";
 
 
 
270
  }
271
 
272
+ echo '<li>
273
+ <a href="javascript:;" class="" data-post_id="' . $post->ID . '">' . $title . '<span class="remove"></span></a>
274
+ <input type="hidden" name="' . $field['name'] . '[]" value="' . $post->ID . '" />
275
+ </li>';
276
+ }
277
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
 
279
+ ?>
280
+ </ul>
281
+ </div>
282
+ <!-- / Right List -->
283
+
284
+ </div>
285
  <?php
286
 
287
 
299
  *-------------------------------------------------------------------------------------*/
300
 
301
  function create_options($key, $field)
302
+ {
303
+ // vars
304
+ $defaults = array(
305
+ 'post_type' => '',
306
+ 'max' => '',
307
+ 'taxonomy' => array('all'),
308
+ );
309
+
310
+ $field = array_merge($defaults, $field);
311
+
312
  ?>
313
  <tr class="field_option field_option_<?php echo $this->name; ?>">
314
  <td class="label">
316
  </td>
317
  <td>
318
  <?php
 
319
 
320
+ $choices = array(
321
+ '' => __("All",'acf')
322
+ );
323
+
324
+ $post_types = get_post_types( array('public' => true) );
325
+
326
+ foreach( $post_types as $post_type )
327
+ {
328
+ $choices[$post_type] = $post_type;
329
  }
330
 
331
  $this->parent->create_field(array(
332
  'type' => 'select',
333
  'name' => 'fields['.$key.'][post_type]',
334
  'value' => $field['post_type'],
335
+ 'choices' => $choices,
336
  'multiple' => '1',
337
  ));
338
+
339
  ?>
340
  </td>
341
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
  <tr class="field_option field_option_<?php echo $this->name; ?>">
343
  <td class="label">
344
  <label><?php _e("Filter from Taxonomy",'acf'); ?></label>
365
  <tr class="field_option field_option_<?php echo $this->name; ?>">
366
  <td class="label">
367
  <label><?php _e("Maximum posts",'acf'); ?></label>
 
368
  </td>
369
  <td>
370
  <?php
376
  ?>
377
  </td>
378
  </tr>
 
 
 
379
  <?php
380
  }
381
 
382
 
383
  /*--------------------------------------------------------------------------------------
384
  *
385
+ * get_value
386
  *
387
  * @author Elliot Condon
388
+ * @since 3.3.3
389
  *
390
  *-------------------------------------------------------------------------------------*/
391
 
392
+ function get_value($post_id, $field)
393
  {
394
+ // get value
395
  $value = parent::get_value($post_id, $field);
 
396
 
397
+
398
+ // empty?
399
+ if( !$value )
400
  {
401
+ return $value;
402
  }
403
 
 
404
 
405
+ // Pre 3.3.3, the value is a string coma seperated
406
+ if( !is_array($value) )
407
  {
408
+ $value = explode(',', $value);
 
 
 
 
 
 
 
 
 
409
  }
410
+
411
+
412
+ // empty?
413
+ if( empty($value) )
414
  {
415
+ return $value;
416
  }
417
 
418
+
419
+ // find posts (DISTINCT POSTS)
420
+ $posts = get_posts(array(
421
+ 'numberposts' => -1,
422
+ 'post__in' => $value,
423
+ 'post_type' => get_post_types( array('public' => true) ),
424
+ 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
425
+ ));
426
+
427
+
428
+ $ordered_posts = array();
429
+ foreach( $posts as $post )
430
+ {
431
+ // create array to hold value data
432
+ $ordered_posts[ $post->ID ] = $post;
433
+ }
434
+
435
+
436
+ // override value array with attachments
437
+ foreach( $value as $k => $v)
438
+ {
439
+ $value[ $k ] = $ordered_posts[ $v ];
440
+ }
441
+
442
+
443
+ // return value
444
+ return $value;
445
  }
446
 
447
 
css/fields.css CHANGED
@@ -598,9 +598,13 @@ table.acf_input table.acf_cf_meta select {
598
  *---------------------------------------------------------------------------------------------*/
599
  #acf_fields select optgroup,
600
  #acf_location select optgroup {
601
- padding: 5px;
602
- background: #F9F9F9;
603
- border-bottom: #DFDFDF solid 1px;
 
 
 
 
604
  }
605
 
606
  #acf_fields select option,
@@ -615,5 +619,5 @@ table.acf_input table.acf_cf_meta select {
615
 
616
  #acf_fields select optgroup:nth-child(2n),
617
  #acf_location select optgroup:nth-child(2n) {
618
- background: #FCFCFC;
619
  }
598
  *---------------------------------------------------------------------------------------------*/
599
  #acf_fields select optgroup,
600
  #acf_location select optgroup {
601
+ padding: 5px 2px;
602
+ background: #fff;
603
+ }
604
+
605
+ #acf_fields select optgroup:first-child,
606
+ #acf_location select optgroup:first-child {
607
+
608
  }
609
 
610
  #acf_fields select option,
619
 
620
  #acf_fields select optgroup:nth-child(2n),
621
  #acf_location select optgroup:nth-child(2n) {
622
+ background: #F9F9F9;
623
  }
css/input.css CHANGED
@@ -548,8 +548,10 @@ ul.checkbox_list {
548
 
549
 
550
  /*---------------------------------------------------------------------------------------------
551
- relationship
552
- ---------------------------------------------------------------------------------------------*/
 
 
553
 
554
  .acf_relationship {
555
  position: relative;
@@ -603,26 +605,31 @@ ul.checkbox_list {
603
  border-top-width: 0;
604
  }
605
 
606
- .acf_relationship .relationship_list a.hide {
607
- display: none;
608
  }
609
 
610
- .acf_relationship .relationship_list a.filter_hide {
611
- display: none;
 
 
 
 
 
 
 
612
  }
613
 
614
- .acf_relationship .relationship_list a {
615
  display: block;
616
  position: relative;
617
  padding: 7px 9px;
618
  text-decoration: none;
619
- border-bottom: #f8f8f8 solid 1px;
620
  }
621
 
622
-
623
- .acf_relationship .relationship_list a:hover {
624
  background: #eaf2fa;
625
- border-bottom-color: #eaf2fa;
626
  color: #000;
627
  }
628
 
@@ -632,12 +639,12 @@ ul.checkbox_list {
632
  border-top-width:1px;
633
  }
634
 
635
- .acf_relationship .relationship_list a .add {
636
  width: 16px;
637
  height: 16px;
638
  background: url(../images/button_add.png) 0 0 no-repeat;
639
  position: absolute;
640
- top:0;
641
  right: 0;
642
  cursor: pointer;
643
  margin: 5px 9px 0 0;
@@ -646,24 +653,24 @@ ul.checkbox_list {
646
  border-radius: 8px;
647
  }
648
 
649
- .acf_relationship .relationship_list a.sortable_active {
650
- background: #eaf2fa;
651
  }
652
 
653
- .acf_relationship .relationship_list a:hover .add {
654
- display: block;
655
  }
656
 
657
- .acf_relationship .relationship_list a .add:hover {
658
  background-position: 0 100%;
659
  }
660
 
661
- .acf_relationship .relationship_list a .remove {
662
  width: 16px;
663
  height: 16px;
664
  background: url(../images/button_remove.png) 0 0 no-repeat;
665
  position: absolute;
666
- top:0;
667
  right: 0;
668
  cursor: pointer;
669
  margin: 5px 9px 0 0;
@@ -672,18 +679,28 @@ ul.checkbox_list {
672
  border-radius: 8px;
673
  }
674
 
675
- .acf_relationship .relationship_list a:hover .remove {
676
  display: block;
677
  }
678
 
679
- .acf_relationship .relationship_list a .remove:hover {
680
  background-position: 0 100%;
681
  }
682
 
683
- .acf_relationship .relationship_right .relationship_list a {
684
  cursor: move;
685
  }
686
 
 
 
 
 
 
 
 
 
 
 
687
 
688
  /*---------------------------------------------------------------------------------------------
689
  Flexible Content
548
 
549
 
550
  /*---------------------------------------------------------------------------------------------
551
+ *
552
+ * Relationship
553
+ *
554
+ *---------------------------------------------------------------------------------------------*/
555
 
556
  .acf_relationship {
557
  position: relative;
605
  border-top-width: 0;
606
  }
607
 
608
+ .acf_relationship .relationship_list li.hide {
609
+ background: #f8f8f8;
610
  }
611
 
612
+ .acf_relationship .relationship_list li.hide a {
613
+ cursor: default;
614
+ color: #21759B !important;
615
+ opacity: 0.5;
616
+ background: transparent !important;
617
+ }
618
+
619
+ .acf_relationship .relationship_list li {
620
+ border-bottom: #f8f8f8 solid 1px;
621
  }
622
 
623
+ .acf_relationship .relationship_list li a {
624
  display: block;
625
  position: relative;
626
  padding: 7px 9px;
627
  text-decoration: none;
 
628
  }
629
 
630
+ .acf_relationship .relationship_list li a:hover,
631
+ .acf_relationship .relationship_list li a:focus {
632
  background: #eaf2fa;
 
633
  color: #000;
634
  }
635
 
639
  border-top-width:1px;
640
  }
641
 
642
+ .acf_relationship .relationship_list li a .add {
643
  width: 16px;
644
  height: 16px;
645
  background: url(../images/button_add.png) 0 0 no-repeat;
646
  position: absolute;
647
+ top: 2px;
648
  right: 0;
649
  cursor: pointer;
650
  margin: 5px 9px 0 0;
653
  border-radius: 8px;
654
  }
655
 
656
+ .acf_relationship .relationship_list li a:hover .add {
657
+ display: block;
658
  }
659
 
660
+ .acf_relationship .relationship_list li.hide a:hover .add {
661
+ display: none;
662
  }
663
 
664
+ .acf_relationship .relationship_list li a .add:hover {
665
  background-position: 0 100%;
666
  }
667
 
668
+ .acf_relationship .relationship_list li a .remove {
669
  width: 16px;
670
  height: 16px;
671
  background: url(../images/button_remove.png) 0 0 no-repeat;
672
  position: absolute;
673
+ top: 2px;
674
  right: 0;
675
  cursor: pointer;
676
  margin: 5px 9px 0 0;
679
  border-radius: 8px;
680
  }
681
 
682
+ .acf_relationship .relationship_list li a:hover .remove {
683
  display: block;
684
  }
685
 
686
+ .acf_relationship .relationship_list li a .remove:hover {
687
  background-position: 0 100%;
688
  }
689
 
690
+ .acf_relationship .relationship_right .relationship_list li a {
691
  cursor: move;
692
  }
693
 
694
+ .acf_relationship .load-more .acf-loading {
695
+ padding: 0;
696
+ box-shadow: none;
697
+ background-color: transparent;
698
+ }
699
+
700
+ .acf_relationship.no-results .load-more {
701
+ display: none;
702
+ }
703
+
704
 
705
  /*---------------------------------------------------------------------------------------------
706
  Flexible Content
js/input-actions.js CHANGED
@@ -151,10 +151,18 @@ var acf = {
151
  validation = true;
152
  }
153
 
154
- // checkbox
155
- if($(this).find('.acf_relationship').exists() && $(this).find('input[type="hidden"]').val() != "")
156
  {
157
- validation = true;
 
 
 
 
 
 
 
 
158
  }
159
 
160
  // repeater
@@ -172,7 +180,6 @@ var acf = {
172
 
173
  }
174
 
175
-
176
  // flexible content
177
  if($(this).find('.acf_flexible_content').exists())
178
  {
@@ -187,7 +194,6 @@ var acf = {
187
 
188
  }
189
 
190
-
191
  // gallery
192
  if($(this).find('.acf-gallery').exists())
193
  {
@@ -202,7 +208,6 @@ var acf = {
202
 
203
  }
204
 
205
-
206
  // set validation
207
  if(!validation)
208
  {
@@ -420,78 +425,104 @@ var acf = {
420
  });
421
 
422
 
423
- /*
 
424
  * Field: Relationship
425
  *
426
  * @description:
427
  * @created: 3/03/2011
428
- */
 
429
 
 
430
  $(document).live('acf/setup_fields', function(e, postbox){
431
 
432
  $(postbox).find('.acf_relationship').each(function(){
433
 
434
  $(this).find('.relationship_right .relationship_list').unbind('sortable').sortable({
435
  axis: "y", // limit the dragging to up/down only
436
- items: 'a:not(.hide)',
437
- start: function(event, ui)
438
- {
439
- ui.item.addClass('sortable_active');
440
- },
441
- stop: function(event, ui)
442
- {
443
- ui.item.removeClass('sortable_active');
444
- ui.item.closest('.acf_relationship').update_acf_relationship_value();
445
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  });
447
 
 
 
 
 
448
  });
449
 
450
  });
451
 
452
 
453
- // updates the input value of a relationship field
454
- $.fn.update_acf_relationship_value = function(){
455
-
456
- // vars
457
- var div = $(this);
458
- var value = "";
459
-
460
- // add id's to array
461
- div.find('.relationship_right .relationship_list a:not(.hide)').each(function(){
462
- value += $(this).attr('data-post_id') + ",";
463
- });
464
-
465
- // remove last ","
466
- value = value.slice(0, -1);
467
-
468
- // set value
469
- div.children('input').val(value);
470
-
471
- };
472
-
473
  // add from left to right
474
  $('.acf_relationship .relationship_left .relationship_list a').live('click', function(){
475
 
476
  // vars
477
- var id = $(this).attr('data-post_id');
478
- var div = $(this).closest('.acf_relationship');
479
- var max = parseInt(div.attr('data-max')); if(max == -1){ max = 9999; }
480
- var right = div.find('.relationship_right .relationship_list');
 
 
481
 
482
  // max posts
483
- if(right.find('a:not(.hide)').length >= max)
484
  {
485
  alert( acf.text.relationship_max_alert.replace('{max}', max) );
486
  return false;
487
  }
488
-
 
 
 
 
 
 
 
 
489
  // hide / show
490
- $(this).addClass('hide');
491
- right.find('a[data-post_id="' + id + '"]').removeClass('hide').appendTo(right);
 
 
 
 
 
 
 
 
 
 
492
 
493
- // update input value
494
- div.update_acf_relationship_value();
495
 
496
  // validation
497
  div.closest('.field').removeClass('error');
@@ -500,53 +531,52 @@ var acf = {
500
 
501
  });
502
 
 
503
  // remove from right to left
504
  $('.acf_relationship .relationship_right .relationship_list a').live('click', function(){
505
 
506
  // vars
507
- var id = $(this).attr('data-post_id');
508
- var div = $(this).closest('.acf_relationship');
509
- var left = div.find('.relationship_left .relationship_list');
 
 
 
 
 
 
 
 
510
 
511
- // hide / show
512
- $(this).addClass('hide');
513
- left.find('a[data-post_id="' + id + '"]').removeClass('hide');
514
 
515
- // update input value
516
- div.update_acf_relationship_value();
517
-
518
  return false;
519
 
520
  });
521
 
522
 
523
- // search left
524
- $.expr[':'].Contains = function(a,i,m){
525
- return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
526
- };
527
- $('.acf_relationship input.relationship_search').live('change', function()
528
  {
529
  // vars
530
- var filter = $(this).val();
531
- var div = $(this).closest('.acf_relationship');
532
- var left = div.find('.relationship_left .relationship_list');
533
-
534
- if(filter)
535
- {
536
- left.find("a:not(:Contains(" + filter + "))").addClass('filter_hide');
537
- left.find("a:Contains(" + filter + "):not(.hide)").removeClass('filter_hide');
538
- }
539
- else
540
- {
541
- left.find("a:not(.hide)").removeClass('filter_hide');
542
- }
543
-
 
 
544
  return false;
545
 
546
  })
547
- .live('keyup', function(){
548
- $(this).change();
549
- })
550
  .live('focus', function(){
551
  $(this).siblings('label').hide();
552
  })
@@ -558,6 +588,103 @@ var acf = {
558
  });
559
 
560
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
561
 
562
  /*
563
  * Field: WYSIWYG
151
  validation = true;
152
  }
153
 
154
+ // relationship
155
+ if($(this).find('.acf_relationship').exists())
156
  {
157
+ if($(this).find('.acf_relationship .relationship_right input').exists())
158
+ {
159
+ validation = true;
160
+ }
161
+ else
162
+ {
163
+ validation = false;
164
+ }
165
+
166
  }
167
 
168
  // repeater
180
 
181
  }
182
 
 
183
  // flexible content
184
  if($(this).find('.acf_flexible_content').exists())
185
  {
194
 
195
  }
196
 
 
197
  // gallery
198
  if($(this).find('.acf-gallery').exists())
199
  {
208
 
209
  }
210
 
 
211
  // set validation
212
  if(!validation)
213
  {
425
  });
426
 
427
 
428
+ /*--------------------------------------------------------------------------------------
429
+ *
430
  * Field: Relationship
431
  *
432
  * @description:
433
  * @created: 3/03/2011
434
+ *
435
+ *-------------------------------------------------------------------------------------*/
436
 
437
+ // add sortable
438
  $(document).live('acf/setup_fields', function(e, postbox){
439
 
440
  $(postbox).find('.acf_relationship').each(function(){
441
 
442
  $(this).find('.relationship_right .relationship_list').unbind('sortable').sortable({
443
  axis: "y", // limit the dragging to up/down only
444
+ items: '> li',
445
+ forceHelperSize: true,
446
+ forcePlaceholderSize: true,
447
+ scroll: true
448
+ });
449
+
450
+
451
+ // load more
452
+ $(this).find('.relationship_left .relationship_list').scrollTop(0).unbind('scroll').scroll( function(){
453
+
454
+ // vars
455
+ var div = $(this).closest('.acf_relationship');
456
+
457
+
458
+ // validate
459
+ if( div.hasClass('loading') )
460
+ {
461
+ return;
462
+ }
463
+
464
+
465
+ // Scrolled to bottom
466
+ if( $(this).scrollTop() + $(this).innerHeight() >= $(this).get(0).scrollHeight )
467
+ {
468
+ var paged = parseInt( div.attr('data-paged') );
469
+
470
+ div.attr('data-paged', (paged + 1) );
471
+
472
+ acf.relationship_update_results( div );
473
+ }
474
+
475
  });
476
 
477
+
478
+ // ajax fetch values for left side
479
+ acf.relationship_update_results( $(this) );
480
+
481
  });
482
 
483
  });
484
 
485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
  // add from left to right
487
  $('.acf_relationship .relationship_left .relationship_list a').live('click', function(){
488
 
489
  // vars
490
+ var id = $(this).attr('data-post_id'),
491
+ title = $(this).text(),
492
+ div = $(this).closest('.acf_relationship'),
493
+ max = parseInt(div.attr('data-max')),
494
+ right = div.find('.relationship_right .relationship_list');
495
+
496
 
497
  // max posts
498
+ if( right.find('a').length >= max )
499
  {
500
  alert( acf.text.relationship_max_alert.replace('{max}', max) );
501
  return false;
502
  }
503
+
504
+
505
+ // can be added?
506
+ if( $(this).parent().hasClass('hide') )
507
+ {
508
+ return false;
509
+ }
510
+
511
+
512
  // hide / show
513
+ $(this).parent().addClass('hide');
514
+
515
+
516
+ // create new li for right side
517
+ var new_li = div.children('.tmpl-li').html()
518
+ .replace( /\{post_id}/gi, id )
519
+ .replace( /\{title}/gi, title );
520
+
521
+
522
+
523
+ // add new li
524
+ right.append( new_li );
525
 
 
 
526
 
527
  // validation
528
  div.closest('.field').removeClass('error');
531
 
532
  });
533
 
534
+
535
  // remove from right to left
536
  $('.acf_relationship .relationship_right .relationship_list a').live('click', function(){
537
 
538
  // vars
539
+ var id = $(this).attr('data-post_id'),
540
+ div = $(this).closest('.acf_relationship'),
541
+ left = div.find('.relationship_left .relationship_list');
542
+
543
+
544
+ // hide
545
+ $(this).parent().remove();
546
+
547
+
548
+ // show
549
+ left.find('a[data-post_id="' + id + '"]').parent('li').removeClass('hide');
550
 
 
 
 
551
 
 
 
 
552
  return false;
553
 
554
  });
555
 
556
 
557
+ // search
558
+ $('.acf_relationship input.relationship_search').live('keyup', function()
 
 
 
559
  {
560
  // vars
561
+ var val = $(this).val(),
562
+ div = $(this).closest('.acf_relationship');
563
+
564
+
565
+ // update data-s
566
+ div.attr('data-s', val);
567
+
568
+
569
+ // new search, reset paged
570
+ div.attr('data-paged', 1);
571
+
572
+
573
+ // ajax
574
+ acf.relationship_update_results( div );
575
+
576
+
577
  return false;
578
 
579
  })
 
 
 
580
  .live('focus', function(){
581
  $(this).siblings('label').hide();
582
  })
588
  });
589
 
590
 
591
+ // hide results
592
+ acf.relationship_hide_results = function( div ){
593
+
594
+ // vars
595
+ var left = div.find('.relationship_left .relationship_list'),
596
+ right = div.find('.relationship_right .relationship_list');
597
+
598
+
599
+ // apply .hide to left li's
600
+ left.find('a').each(function(){
601
+
602
+ var id = $(this).attr('data-post_id');
603
+
604
+ if( right.find('a[data-post_id="' + id + '"]').exists() )
605
+ {
606
+ $(this).parent().addClass('hide');
607
+ }
608
+
609
+ });
610
+
611
+ }
612
+
613
+
614
+ // update results
615
+ acf.relationship_update_results = function( div ){
616
+
617
+
618
+ // add loading class, stops scroll loading
619
+ div.addClass('loading');
620
+
621
+
622
+ // abort previous request
623
+ if( acf.relationship_xhr )
624
+ {
625
+ acf.relationship_xhr.abort();
626
+ }
627
+
628
+
629
+ // vars
630
+ var s = div.attr('data-s'),
631
+ paged = parseInt( div.attr('data-paged') ),
632
+ taxonomy = div.attr('data-taxonomy'),
633
+ post_type = div.attr('data-post_type'),
634
+ left = div.find('.relationship_left .relationship_list'),
635
+ right = div.find('.relationship_right .relationship_list');
636
+
637
+
638
+ // get results
639
+ acf.relationship_xhr = $.ajax({
640
+ url: ajaxurl,
641
+ type: 'post',
642
+ dataType: 'html',
643
+ data: {
644
+ 'action' : 'acf_get_relationship_results',
645
+ 's' : s,
646
+ 'paged' : paged,
647
+ 'taxonomy' : taxonomy,
648
+ 'post_type' : post_type
649
+ },
650
+ success: function( html ){
651
+
652
+ div.removeClass('no-results').removeClass('loading');
653
+
654
+ // no results?
655
+ if( !html )
656
+ {
657
+ div.addClass('no-results');
658
+ return;
659
+ }
660
+
661
+
662
+ // new search?
663
+ if( paged == 1 )
664
+ {
665
+ left.find('li:not(.load-more)').remove();
666
+ }
667
+
668
+
669
+ // append new results
670
+ left.find('.load-more').before( html );
671
+
672
+
673
+ // less than 10 results?
674
+ var ul = $('<ul>' + html + '</ul>');
675
+ if( ul.find('li').length < 10 )
676
+ {
677
+ div.addClass('no-results');
678
+ }
679
+
680
+
681
+ // hide values
682
+ acf.relationship_hide_results( div );
683
+
684
+ }
685
+ });
686
+ };
687
+
688
 
689
  /*
690
  * Field: WYSIWYG
readme.txt CHANGED
@@ -85,6 +85,11 @@ http://www.advancedcustomfields.com/support/
85
 
86
  == Changelog ==
87
 
 
 
 
 
 
88
  = 3.3.2 =
89
  * [Fixed] Integrate with Shopp plugin
90
 
85
 
86
  == Changelog ==
87
 
88
+ = 3.3.3 =
89
+ * [Upgrade] Database Upgrade is required to modify the taxonomy filtering data for fields. This allows for performance boosts throughout ACF.
90
+ * [Improved] relationship field: Improve querying posts / results and use AJAX powered search to increase performance on large-scale websites
91
+ * [Improved] post object field: Improve querying posts / results
92
+
93
  = 3.3.2 =
94
  * [Fixed] Integrate with Shopp plugin
95