abstract-acf-legacy-location.php
6 months ago
abstract-acf-location.php
1 month ago
class-acf-location-attachment.php
1 month ago
class-acf-location-comment.php
6 months ago
class-acf-location-current-user-role.php
1 month ago
class-acf-location-current-user.php
1 month ago
class-acf-location-nav-menu-item.php
6 months ago
class-acf-location-nav-menu.php
1 month ago
class-acf-location-page-parent.php
6 months ago
class-acf-location-page-template.php
1 month ago
class-acf-location-page-type.php
1 month ago
class-acf-location-page.php
6 months ago
class-acf-location-post-category.php
6 months ago
class-acf-location-post-format.php
6 months ago
class-acf-location-post-status.php
6 months ago
class-acf-location-post-taxonomy.php
1 month ago
class-acf-location-post-template.php
1 month ago
class-acf-location-post-type.php
1 month ago
class-acf-location-post.php
6 months ago
class-acf-location-taxonomy.php
1 month ago
class-acf-location-user-form.php
1 month ago
class-acf-location-user-role.php
1 month ago
class-acf-location-widget.php
6 months ago
index.php
2 years ago
class-acf-location-post.php
103 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 ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; // Exit if accessed directly |
| 14 | } |
| 15 | |
| 16 | if ( ! class_exists( 'ACF_Location_Post' ) ) : |
| 17 | |
| 18 | class ACF_Location_Post extends ACF_Location { |
| 19 | |
| 20 | /** |
| 21 | * Initializes props. |
| 22 | * |
| 23 | * @date 5/03/2014 |
| 24 | * @since 5.0.0 |
| 25 | * |
| 26 | * @param void |
| 27 | * @return void |
| 28 | */ |
| 29 | public function initialize() { |
| 30 | $this->name = 'post'; |
| 31 | $this->label = __( 'Post', 'acf' ); |
| 32 | $this->category = 'post'; |
| 33 | $this->object_type = 'post'; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Matches the provided rule against the screen args returning a bool result. |
| 38 | * |
| 39 | * @date 9/4/20 |
| 40 | * @since 5.9.0 |
| 41 | * |
| 42 | * @param array $rule The location rule. |
| 43 | * @param array $screen The screen args. |
| 44 | * @param array $field_group The field group settings. |
| 45 | * @return boolean |
| 46 | */ |
| 47 | public function match( $rule, $screen, $field_group ) { |
| 48 | |
| 49 | // Check screen args. |
| 50 | if ( isset( $screen['post_id'] ) ) { |
| 51 | $post_id = $screen['post_id']; |
| 52 | } else { |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | // Compare rule against post_id. |
| 57 | return $this->compare_to_rule( $post_id, $rule ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns an array of possible values for this rule type. |
| 62 | * |
| 63 | * @date 9/4/20 |
| 64 | * @since 5.9.0 |
| 65 | * |
| 66 | * @param array $rule A location rule. |
| 67 | * @return array |
| 68 | */ |
| 69 | public function get_values( $rule ) { |
| 70 | $choices = array(); |
| 71 | |
| 72 | // Get post types. |
| 73 | $post_types = acf_get_post_types( |
| 74 | array( |
| 75 | 'show_ui' => 1, |
| 76 | 'exclude' => array( 'page', 'attachment' ), |
| 77 | ) |
| 78 | ); |
| 79 | |
| 80 | // Get grouped posts. |
| 81 | $groups = acf_get_grouped_posts( |
| 82 | array( |
| 83 | 'post_type' => $post_types, |
| 84 | ) |
| 85 | ); |
| 86 | |
| 87 | // Append to choices. |
| 88 | if ( $groups ) { |
| 89 | foreach ( $groups as $label => $posts ) { |
| 90 | $choices[ $label ] = array(); |
| 91 | foreach ( $posts as $post ) { |
| 92 | $choices[ $label ][ $post->ID ] = acf_get_post_title( $post ); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | return $choices; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | // initialize |
| 101 | acf_register_location_type( 'ACF_Location_Post' ); |
| 102 | endif; // class_exists check |
| 103 |