PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields (ACF®) / 6.8.8
Advanced Custom Fields (ACF®) v6.8.8
6.8.9 6.8.8 6.8.7 6.8.6 6.8.5 6.8.4 6.8.3 6.8.2 6.8.1 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.2 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 6.1.0 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.1.6 6.1.7 6.1.8 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.6.1 6.2.7 6.2.8 6.2.9 6.3.0 6.3.1 6.3.10.2 6.3.11 6.3.12 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.6.1 6.4.0 6.4.0.1 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.6.0 6.6.1 6.6.2 6.7.0 6.7.1 6.7.2 6.8.0 trunk 1.0.0 1.0.2 1.0.3 1.0.5 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.1 2.1.3 2.1.4 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.6 3.0.7 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.8 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.10 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 5.10 5.10.1 5.10.2 5.11 5.11.1 5.11.2 5.11.3 5.11.4 5.12 5.12.1 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.6.10 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 5.6.8 5.6.9 5.7.0 5.7.1 5.7.10 5.7.12 5.7.13 5.7.2 5.7.3 5.7.4 5.7.5 5.7.6 5.7.7 5.7.8 5.7.9 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.2 5.8.3 5.8.4
advanced-custom-fields / includes / fields / class-acf-field-page_link.php
advanced-custom-fields / includes / fields Last commit date
class-acf-field-accordion.php 5 months ago class-acf-field-button-group.php 5 months ago class-acf-field-checkbox.php 2 months ago class-acf-field-color_picker.php 5 months ago class-acf-field-date_picker.php 5 months ago class-acf-field-date_time_picker.php 5 months ago class-acf-field-email.php 5 months ago class-acf-field-file.php 5 months ago class-acf-field-google-map.php 5 months ago class-acf-field-group.php 5 months ago class-acf-field-icon_picker.php 6 months ago class-acf-field-image.php 1 month ago class-acf-field-link.php 5 months ago class-acf-field-message.php 6 months ago class-acf-field-number.php 5 months ago class-acf-field-oembed.php 2 months ago class-acf-field-output.php 6 months ago class-acf-field-page_link.php 1 month ago class-acf-field-password.php 5 months ago class-acf-field-post_object.php 1 month ago class-acf-field-radio.php 2 months ago class-acf-field-range.php 5 months ago class-acf-field-relationship.php 1 month ago class-acf-field-select.php 2 months ago class-acf-field-separator.php 6 months ago class-acf-field-tab.php 6 months ago class-acf-field-taxonomy.php 2 months ago class-acf-field-text.php 5 months ago class-acf-field-textarea.php 5 months ago class-acf-field-time_picker.php 5 months ago class-acf-field-true_false.php 5 months ago class-acf-field-url.php 5 months ago class-acf-field-user.php 2 months ago class-acf-field-wysiwyg.php 5 months ago class-acf-field.php 5 months ago index.php 2 years ago
class-acf-field-page_link.php
759 lines
1 <?php
2 /**
3 * @package ACF
4 * @author WP Engine
5 *
6 * © 2026 Advanced Custom Fields (ACF®). All rights reserved.
7 * "ACF" is a trademark of WP Engine.
8 * Licensed under the GNU General Public License v2 or later.
9 * https://www.gnu.org/licenses/gpl-2.0.html
10 */
11
12 if ( ! class_exists( 'acf_field_page_link' ) ) :
13
14 class acf_field_page_link extends acf_field {
15
16
17 /**
18 * This function will setup the field type data
19 *
20 * @type function
21 * @date 5/03/2014
22 * @since 5.0.0
23 *
24 * @param n/a
25 * @return n/a
26 */
27 function initialize() {
28
29 // vars
30 $this->name = 'page_link';
31 $this->label = __( 'Page Link', 'acf' );
32 $this->category = 'relational';
33 $this->description = __( 'An interactive dropdown to select one or more posts, pages, custom post type items or archive URLs, with the option to search.', 'acf' );
34 $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-page-link.png';
35 $this->doc_url = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/page-link/', 'docs', 'field-type-selection' );
36 $this->defaults = array(
37 'post_type' => array(),
38 'taxonomy' => array(),
39 'allow_null' => 0,
40 'multiple' => 0,
41 'allow_archives' => 1,
42 );
43
44 // extra
45 add_action( 'wp_ajax_acf/fields/page_link/query', array( $this, 'ajax_query' ) );
46 add_action( 'wp_ajax_nopriv_acf/fields/page_link/query', array( $this, 'ajax_query' ) );
47 add_filter( 'acf/conditional_logic/choices', array( $this, 'render_field_page_link_conditional_choices' ), 10, 3 );
48 }
49
50 /**
51 * Filters choices in page link conditions.
52 *
53 * @since 6.3
54 *
55 * @param array $choices The selected choice.
56 * @param array $conditional_field The conditional field settings object.
57 * @param string $rule_value The rule value.
58 * @return array
59 */
60 public function render_field_page_link_conditional_choices( $choices, $conditional_field, $rule_value ) {
61 if ( ! is_array( $conditional_field ) || $conditional_field['type'] !== 'page_link' ) {
62 return $choices;
63 }
64 if ( ! empty( $rule_value ) ) {
65 $post_title = esc_html( get_the_title( $rule_value ) );
66 $choices = array( $rule_value => $post_title );
67 }
68 return $choices;
69 }
70
71 /**
72 * Returns AJAX results for the Page Link field.
73 *
74 * @since 5.0.0
75 *
76 * @return void
77 */
78 public function ajax_query() {
79 $nonce = acf_request_arg( 'nonce', '' );
80 $key = acf_request_arg( 'field_key', '' );
81 $conditional_logic = (bool) acf_request_arg( 'conditional_logic', false );
82
83 if ( $conditional_logic ) {
84 if ( ! acf_current_user_can_admin() ) {
85 die();
86 }
87
88 // Use the standard ACF admin nonce.
89 $nonce = '';
90 $key = '';
91 }
92
93 if ( ! acf_verify_ajax( $nonce, $key, ! $conditional_logic, 'page_link' ) ) {
94 die();
95 }
96
97 // defaults
98 $options = acf_parse_args(
99 $_POST,
100 array(
101 'post_id' => 0,
102 's' => '',
103 'field_key' => '',
104 'paged' => 1,
105 'include' => '',
106 )
107 );
108
109 // vars
110 $results = array();
111 $args = array();
112 $s = false;
113 $is_search = false;
114
115 // paged
116 $args['posts_per_page'] = 20;
117 $args['paged'] = (int) $options['paged'];
118
119 // search
120 if ( $options['s'] !== '' ) {
121
122 // strip slashes (search may be integer)
123 $s = wp_unslash( strval( $options['s'] ) );
124
125 // update vars
126 $args['s'] = $s;
127 $is_search = true;
128 }
129
130 // load field
131 $field = acf_get_field( $options['field_key'] );
132 if ( ! $field ) {
133 die();
134 }
135
136 // update $args
137 if ( ! empty( $field['post_type'] ) ) {
138 $args['post_type'] = acf_get_array( $field['post_type'] );
139 } else {
140 $args['post_type'] = acf_get_post_types();
141 }
142
143 // Post status - use field config only, don't accept from user input.
144 if ( ! empty( $field['post_status'] ) ) {
145 $args['post_status'] = acf_get_array( $field['post_status'] );
146 }
147
148 // create tax queries
149 if ( ! empty( $field['taxonomy'] ) ) {
150
151 // append to $args
152 $args['tax_query'] = array();
153
154 // decode terms
155 $taxonomies = acf_decode_taxonomy_terms( $field['taxonomy'] );
156
157 // now create the tax queries
158 foreach ( $taxonomies as $taxonomy => $terms ) {
159 $args['tax_query'][] = array(
160 'taxonomy' => $taxonomy,
161 'field' => 'slug',
162 'terms' => $terms,
163 );
164 }
165 }
166
167 if ( ! empty( $options['include'] ) ) {
168 $args['include'] = (int) $options['include'];
169 }
170
171 $args['perm'] = 'readable';
172 $args = acf_ensure_perm_readable_post_status( $args );
173
174 // filters
175 $args = apply_filters( 'acf/fields/page_link/query', $args, $field, $options['post_id'] );
176 $args = apply_filters( 'acf/fields/page_link/query/name=' . $field['name'], $args, $field, $options['post_id'] );
177 $args = apply_filters( 'acf/fields/page_link/query/key=' . $field['key'], $args, $field, $options['post_id'] );
178
179 // Re-normalize in case a filter reset `post_status` to 'any' while leaving `perm=readable`.
180 $args = acf_ensure_perm_readable_post_status( $args );
181
182 // add archives to $results
183 if ( $field['allow_archives'] && $args['paged'] == 1 ) {
184
185 // Generate unique list of URLs.
186 $links = array();
187 $links[] = home_url();
188 foreach ( $args['post_type'] as $post_type ) {
189 $links[] = get_post_type_archive_link( $post_type );
190 }
191 $links = array_filter( $links );
192 $links = array_unique( $links );
193
194 // Convert list into choices.
195 $children = array();
196 foreach ( $links as $link ) {
197
198 // Ignore if search does not match.
199 if ( $is_search && stripos( $link, $s ) === false ) {
200 continue;
201 }
202 $children[] = array(
203 'id' => $link,
204 'text' => $link,
205 );
206 }
207 if ( $children ) {
208 $results[] = array(
209 'text' => __( 'Archives', 'acf' ),
210 'children' => $children,
211 );
212 }
213 }
214
215 // If there is an include set, we will unset search to avoid attempting to further filter by the search term.
216 if ( isset( $args['include'] ) ) {
217 unset( $args['s'] );
218 }
219
220 // get posts grouped by post type
221 $groups = acf_get_grouped_posts( $args );
222
223 // loop
224 if ( ! empty( $groups ) ) {
225 foreach ( array_keys( $groups ) as $group_title ) {
226
227 // vars
228 $posts = acf_extract_var( $groups, $group_title );
229
230 // data
231 $data = array(
232 'text' => $group_title,
233 'children' => array(),
234 );
235
236 // convert post objects to post titles
237 foreach ( array_keys( $posts ) as $post_id ) {
238 $posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'], $is_search );
239 }
240
241 // order posts by search
242 if ( $is_search && empty( $args['orderby'] ) && isset( $args['s'] ) ) {
243 $posts = acf_order_by_search( $posts, $args['s'] );
244 }
245
246 // append to $data
247 foreach ( array_keys( $posts ) as $post_id ) {
248 $data['children'][] = $this->get_post_result( $post_id, $posts[ $post_id ] );
249 }
250
251 // append to $results
252 $results[] = $data;
253 }
254 }
255
256 // return
257 acf_send_ajax_results(
258 array(
259 'results' => $results,
260 'limit' => $args['posts_per_page'],
261 )
262 );
263 }
264
265
266 /**
267 * This function will return an array containing id, text and maybe description data
268 *
269 * @type function
270 * @date 7/07/2016
271 * @since 5.4.0
272 *
273 * @param $id (mixed)
274 * @param $text (string)
275 * @return (array)
276 */
277 function get_post_result( $id, $text ) {
278
279 // vars
280 $result = array(
281 'id' => $id,
282 'text' => $text,
283 );
284
285 // look for parent
286 $search = '| ' . __( 'Parent', 'acf' ) . ':';
287 $pos = strpos( $text, $search );
288
289 if ( $pos !== false ) {
290 $result['description'] = substr( $text, $pos + 2 );
291 $result['text'] = substr( $text, 0, $pos );
292 }
293
294 // return
295 return $result;
296 }
297
298
299 /**
300 * This function returns the HTML for a result
301 *
302 * @type function
303 * @date 1/11/2013
304 * @since 5.0.0
305 *
306 * @param $post (object)
307 * @param $field (array)
308 * @param $post_id (int) the post_id to which this value is saved to
309 * @return (string)
310 */
311 function get_post_title( $post, $field, $post_id = 0, $is_search = 0 ) {
312
313 // get post_id
314 if ( ! $post_id ) {
315 $post_id = acf_get_form_data( 'post_id' );
316 }
317
318 // vars
319 $title = acf_get_post_title( $post, $is_search );
320
321 // filters
322 $title = apply_filters( 'acf/fields/page_link/result', $title, $post, $field, $post_id );
323 $title = apply_filters( 'acf/fields/page_link/result/name=' . $field['_name'], $title, $post, $field, $post_id );
324 $title = apply_filters( 'acf/fields/page_link/result/key=' . $field['key'], $title, $post, $field, $post_id );
325
326 // return
327 return $title;
328 }
329
330
331 /**
332 * This function will return an array of posts for a given field value
333 *
334 * @type function
335 * @date 13/06/2014
336 * @since 5.0.0
337 *
338 * @param $value (array)
339 * @return $value
340 */
341 function get_posts( $value, $field ) {
342
343 // force value to array
344 $value = acf_get_array( $value );
345
346 // get selected post ID's
347 $post__in = array();
348
349 foreach ( $value as $k => $v ) {
350 if ( is_numeric( $v ) ) {
351
352 // append to $post__in
353 $post__in[] = (int) $v;
354 }
355 }
356
357 // bail early if no posts
358 if ( empty( $post__in ) ) {
359 return $value;
360 }
361
362 // get posts
363 $posts = acf_get_posts(
364 array(
365 'post__in' => $post__in,
366 'post_type' => $field['post_type'],
367 )
368 );
369
370 // override value with post
371 $return = array();
372
373 // append to $return
374 foreach ( $value as $k => $v ) {
375 if ( is_numeric( $v ) ) {
376
377 // extract first post
378 $post = array_shift( $posts );
379
380 // append
381 if ( $post ) {
382 $return[] = $post;
383 }
384 } else {
385 $return[] = $v;
386 }
387 }
388
389 // return
390 return $return;
391 }
392
393
394 /**
395 * Renders the Page Link field.
396 *
397 * @since 3.6
398 *
399 * @param array $field The field settings array.
400 * @return void
401 */
402 public function render_field( $field ) {
403 // Change Field into a select
404 $field['type'] = 'select';
405 $field['ui'] = 1;
406 $field['ajax'] = 1;
407 $field['choices'] = array();
408 $field['nonce'] = wp_create_nonce( 'acf_field_' . $this->name . '_' . $field['key'] );
409
410 // populate choices if value exists
411 if ( ! empty( $field['value'] ) ) {
412
413 // get posts
414 $posts = $this->get_posts( $field['value'], $field );
415
416 // set choices
417 if ( ! empty( $posts ) ) {
418 foreach ( array_keys( $posts ) as $i ) {
419
420 // vars
421 $post = acf_extract_var( $posts, $i );
422
423 if ( is_object( $post ) ) {
424
425 // append to choices
426 $field['choices'][ $post->ID ] = $this->get_post_title( $post, $field );
427 } else {
428
429 // append to choices
430 $field['choices'][ $post ] = $post;
431 }
432 }
433 }
434 }
435
436 // render
437 acf_render_field( $field );
438 }
439
440
441 /**
442 * Create extra options for your field. This is rendered when editing a field.
443 * The value of $field['name'] can be used (like bellow) to save extra data to the $field
444 *
445 * @type action
446 * @since 3.6
447 * @date 23/01/13
448 *
449 * @param $field - an array holding all the field's data
450 */
451 function render_field_settings( $field ) {
452 acf_render_field_setting(
453 $field,
454 array(
455 'label' => __( 'Filter by Post Type', 'acf' ),
456 'instructions' => '',
457 'type' => 'select',
458 'name' => 'post_type',
459 'choices' => acf_get_pretty_post_types(),
460 'multiple' => 1,
461 'ui' => 1,
462 'allow_null' => 1,
463 'placeholder' => __( 'All post types', 'acf' ),
464 )
465 );
466
467 acf_render_field_setting(
468 $field,
469 array(
470 'label' => __( 'Filter by Post Status', 'acf' ),
471 'instructions' => '',
472 'type' => 'select',
473 'name' => 'post_status',
474 'choices' => acf_get_pretty_post_statuses(),
475 'multiple' => 1,
476 'ui' => 1,
477 'allow_null' => 1,
478 'placeholder' => __( 'Any post status', 'acf' ),
479 )
480 );
481
482 acf_render_field_setting(
483 $field,
484 array(
485 'label' => __( 'Filter by Taxonomy', 'acf' ),
486 'instructions' => '',
487 'type' => 'select',
488 'name' => 'taxonomy',
489 'choices' => acf_get_taxonomy_terms(),
490 'multiple' => 1,
491 'ui' => 1,
492 'allow_null' => 1,
493 'placeholder' => __( 'All taxonomies', 'acf' ),
494 )
495 );
496
497 acf_render_field_setting(
498 $field,
499 array(
500 'label' => __( 'Allow Archives URLs', 'acf' ),
501 'instructions' => '',
502 'name' => 'allow_archives',
503 'type' => 'true_false',
504 'ui' => 1,
505 )
506 );
507
508 acf_render_field_setting(
509 $field,
510 array(
511 'label' => __( 'Select Multiple', 'acf' ),
512 'instructions' => 'Allow content editors to select multiple values',
513 'name' => 'multiple',
514 'type' => 'true_false',
515 'ui' => 1,
516 )
517 );
518 }
519
520 /**
521 * Renders the field settings used in the "Validation" tab.
522 *
523 * @since 6.0
524 *
525 * @param array $field The field settings array.
526 * @return void
527 */
528 function render_field_validation_settings( $field ) {
529 acf_render_field_setting(
530 $field,
531 array(
532 'label' => __( 'Allow Null', 'acf' ),
533 'instructions' => '',
534 'name' => 'allow_null',
535 'type' => 'true_false',
536 'ui' => 1,
537 )
538 );
539 }
540
541 /**
542 * This filter is appied to the $value after it is loaded from the db and before it is returned to the template
543 *
544 * @type filter
545 * @since 3.6
546 * @date 23/01/13
547 *
548 * @param $value (mixed) the value which was loaded from the database
549 * @param $post_id (mixed) the post_id from which the value was loaded
550 * @param $field (array) the field array holding all the field options
551 *
552 * @return $value (mixed) the modified value
553 */
554 function format_value( $value, $post_id, $field ) {
555
556 // ACF4 null
557 if ( $value === 'null' ) {
558 return false;
559 }
560
561 // bail early if no value
562 if ( empty( $value ) ) {
563 return $value;
564 }
565
566 // get posts
567 $value = $this->get_posts( $value, $field );
568
569 // set choices
570 foreach ( array_keys( $value ) as $i ) {
571
572 // vars
573 $post = acf_extract_var( $value, $i );
574
575 // convert $post to permalink
576 if ( is_object( $post ) ) {
577 $post = get_permalink( $post );
578 }
579
580 // append back to $value
581 $value[ $i ] = $post;
582 }
583
584 // convert back from array if neccessary
585 if ( ! $field['multiple'] ) {
586 $value = array_shift( $value );
587 }
588
589 // return value
590 return $value;
591 }
592
593
594 /**
595 * This filter is appied to the $value before it is updated in the db
596 *
597 * @type filter
598 * @since 3.6
599 * @date 23/01/13
600 *
601 * @param $value - the value which will be saved in the database
602 * @param $post_id - the post_id of which the value will be saved
603 * @param $field - the field array holding all the field options
604 *
605 * @return $value - the modified value
606 */
607 function update_value( $value, $post_id, $field ) {
608
609 // Bail early if no value.
610 if ( empty( $value ) ) {
611 return $value;
612 }
613
614 // Format array of values.
615 // - ensure each value is an id.
616 // - Parse each id as string for SQL LIKE queries.
617 if ( acf_is_sequential_array( $value ) ) {
618 $value = array_map( 'acf_maybe_idval', $value );
619 $value = array_map( 'strval', $value );
620
621 // Parse single value for id.
622 } else {
623 $value = acf_maybe_idval( $value );
624 }
625
626 // Return value.
627 return $value;
628 }
629
630 /**
631 * Validates page link fields updated via the REST API.
632 *
633 * @param boolean $valid The current validity booleean
634 * @param integer $value The value of the field
635 * @param array $field The field array
636 * @return boolean|WP_Error
637 */
638 public function validate_rest_value( $valid, $value, $field ) {
639 return acf_get_field_type( 'post_object' )->validate_rest_value( $valid, $value, $field );
640 }
641
642 /**
643 * Return the schema array for the REST API.
644 *
645 * @param array $field
646 * @return array
647 */
648 public function get_rest_schema( array $field ) {
649 $schema = array(
650 'type' => array( 'integer', 'array', 'null' ),
651 'required' => ! empty( $field['required'] ),
652 'items' => array(
653 'type' => array( 'integer' ),
654 ),
655 );
656
657 if ( empty( $field['allow_null'] ) ) {
658 $schema['minItems'] = 1;
659 }
660
661 if ( ! empty( $field['allow_archives'] ) ) {
662 $schema['type'][] = 'string';
663 $schema['items']['type'][] = 'string';
664 }
665
666 if ( empty( $field['multiple'] ) ) {
667 $schema['maxItems'] = 1;
668 }
669
670 return $schema;
671 }
672
673 /**
674 * @see \acf_field::get_rest_links()
675 * @param mixed $value The raw (unformatted) field value.
676 * @param integer|string $post_id
677 * @param array $field
678 * @return array
679 */
680 public function get_rest_links( $value, $post_id, array $field ) {
681 $links = array();
682
683 if ( empty( $value ) ) {
684 return $links;
685 }
686
687 foreach ( (array) $value as $object_id ) {
688 if ( ! $post_type = get_post_type( $object_id ) or ! $post_type = get_post_type_object( $post_type ) ) {
689 continue;
690 }
691 $rest_base = acf_get_object_type_rest_base( $post_type );
692 $links[] = array(
693 'rel' => $post_type->name === 'attachment' ? 'acf:attachment' : 'acf:post',
694 'href' => rest_url( sprintf( '/wp/v2/%s/%s', $rest_base, $object_id ) ),
695 'embeddable' => true,
696 );
697 }
698
699 return $links;
700 }
701
702 /**
703 * Apply basic formatting to prepare the value for default REST output.
704 *
705 * @param mixed $value
706 * @param string|integer $post_id
707 * @param array $field
708 * @return mixed
709 */
710 public function format_value_for_rest( $value, $post_id, array $field ) {
711 return acf_format_numerics( $value );
712 }
713
714 /**
715 * Formats the field value for JSON-LD output.
716 *
717 * @since 6.8.0
718 *
719 * @param mixed $value The value of the field.
720 * @param integer|string $post_id The ID of the post.
721 * @param array $field The field array.
722 * @return mixed
723 */
724 public function format_value_for_jsonld( $value, $post_id, $field ) {
725 $value = acf_format_numerics( $value );
726
727 if ( ! $value ) {
728 return $value;
729 }
730
731 if ( is_array( $value ) ) {
732 return array_map(
733 function ( $post_id ) {
734 return get_permalink( $post_id );
735 },
736 $value
737 );
738 }
739
740 return get_permalink( $value );
741 }
742
743 /**
744 * Returns an array of JSON-LD Property output types that are supported by this field type.
745 *
746 * @since 6.8
747 *
748 * @return string[]
749 */
750 public function get_jsonld_output_types(): array {
751 return array( 'URL' );
752 }
753 }
754
755
756 // initialize
757 acf_register_field_type( 'acf_field_page_link' );
758 endif; // class_exists check
759