Skip Navigation

[Fermé] 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 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 réponses, has 2 voix.

Last updated by Ana Il y a 5 années et 11 mois.

Assigned support staff: Ana.

Auteur
Publications
#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.

Le sujet ‘[Fermé] Custom field type that list posts in a custom post type or custom taxonomy’ est fermé à de nouvelles réponses.