Home › Forums › General Issues › Custom Post Type as WordPress Front/Home › Reply To: Custom Post Type as WordPress Front/Home
OK, happy days. I found this handy little snippet. I applied it, changed out the values with mine and added it to my functions.php file.
// populate acf field (select_post) with post types (clients)
function acf_load_select_post( $field ) {
$field['choices'] = get_post_type_values( 'clients' );
return $field;
}
add_filter( 'acf/load_field/name=select_post', 'acf_load_select_post' );
function get_post_type_values( $post_type ) {
$values = array();
$defaults = array(
'post_type' => $post_type,
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC'
);
$query = new WP_Query( $defaults );
if ( $query->found_posts > 0 ) {
foreach ( $query->posts as $post ) {
$values[get_the_title( $post->ID )] = get_the_title( $post->ID );
}
}
return $values;
}
This populates the Select field on the page called Home. Huzzah!
Now I just need to create my home page template to populate the page with the content of the selection. That would be the index.php file, right?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.