Last active
January 16, 2023 00:00
-
-
Save mishterk/24f5dc504eb99c93afc7bf03449f083c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'acf/load_field/key=TARGET_FIELD_KEY_HERE', 'afp_test_acf_load_field_filter' ); | |
function afp_test_acf_load_field_filter( $field ) { | |
$field['choices'] = []; | |
// Using get_posts() instead of WP_Query prevents query loop issues and global var overrides that break | |
// functionality on the advanced forms edit screen and potentially other contexts. | |
$posts = get_posts( [ | |
'post_type' => 'post', | |
'posts_per_page' => - 1, | |
'orderby' => 'title', | |
'order' => 'ASC', | |
] ); | |
foreach ( $posts as $post ) { | |
$field['choices'][ $post->ID ] = get_the_title( $post ); | |
} | |
return $field; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment