Skip Navigation

[Resolved] Populate select field with all the posts that are published

This support ticket is created 7 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Noman 7 years, 2 months ago.

Assisted by: Noman.

Author
Posts
#564761

I am looking for a way to populate a select field with all the posts that are published.

I followed https://toolset.com/forums/topic/custom-field-type-that-list-posts-in-a-custom-post-type-or-custom-taxonomy/ but this didn't work for me.

I added this to my theme's functions.php:
add_filter( 'wpt_field_options', 'prefix_custom_options', 10, 3);

function prefix_custom_options( $options, $title, $type ){
switch( $title ){
case 'waar-ben-ik-mee-bezig':
$options = array();
$args = array(
'post_type' => 'post',
'post_status' => 'publish');
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$options[] = array(
'#value' => $post->ID,
'#title' => $post->post_title,
);
}
break;
}
return $options;
}

Did I overlook something?

#564775
#564781

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting Toolset support. Ok since this is duplicated and our supporter Shane is already working on your other ticket. We can close this one.

Have a great day,
Thank you