Skip Navigation

[Closed] Custom field type that list posts in a custom post type or custom taxonomy

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

This topic contains 3 replies, has 2 voices.

Last updated by Ana 9 years, 5 months ago.

Assisted by: Ana.

Author
Posts
#250341

There's a feature I'm always surprised that your plugin doesn't offer.

I often come across the scenario where I'd love to be able to have a dropdown list on the "parent" custom post type where I could select which "child" is relevent.

e.g. If I had an events and a speaker custom post type – I'd want to have a dropdown on the edit events page where I can select the speaker from a list.

If you could do this by dragging a new custom field into a custom field group where you could configure which custom post type or custom taxonomy to list posts from that would be ideal.

#250389

Ana
Supporter

Types has a filter that enables this feature 'wpt_field_options'.

Lets say that you had created a custom group and on that added a custom field of type select with the name 'my select field'.
Now you want to populate that select wherever it is displayed with all the posts that are published.
Just add the following to your functions.php file

//dynamically populate select field from Types
add_filter( 'wpt_field_options', 'prefix_custom_options', 10, 3);

function prefix_custom_options( $options, $title, $type ){
	switch( $title ){
		case 'my-select-field':
			$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;
}

Would this resolve your issue?

#251390

Hi Ana

Thanks so much for this - Ill definitely give this a go.

How would I go about using the above if I wanted the dropdown to be a repeatable field?

Dan

#254143

Ana
Supporter

Currently we do not have the option to allow a custom filed of type select to have multiple-instances, thus making it into a repeatable-field.

The topic ‘[Closed] Custom field type that list posts in a custom post type or custom taxonomy’ is closed to new replies.