Skip Navigation

[Closed] how to populet custom dropdown field with custom post titles?

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.

This topic contains 3 replies, has 2 voices.

Last updated by Christopher Amirian 1 year, 11 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2682566

I am useing this to get select box options from custom post type , but its not working

add_filter( 'wpt_field_options', 'generate_agency_title', 10, 3);

function generate_agency_title( $options, $title, $type ){

switch( $title ){
// run this code only if the field name is projecten-title
case 'agency-name':
$options = array();
$args = array(
'numberposts' => -1,
'post_type' => 'agency', // replace with appropriate post type anme
'post_status' => 'publish');

// Queries all the published posts of post type projecten

$posts_array = get_posts( $args );

foreach ($posts_array as $post) {
$options[] = array(
'#value' => $post->post_title,
'#title' => $post->post_title,
);
}
break;
}
return $options;
}

#2682680

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Let's troubleshoot the issue with fetching select box options from the custom post type agency. Here are some steps to help resolve the issue:

Double-check the field title used in the switch case statement (agency-name) to ensure it matches exactly with the field title as it appears in the WordPress Toolset plugin.

Verify that the custom post type name used in the post_type argument of the get_posts() function (agency) matches the actual name of the custom post type.

Check this as a reference:
https://toolset.com/documentation/programmer-reference/types-api-filters/#wpt_field_options

Thanks.

#2682908
screenshot-actovision.dev-2024.02.12-19_20_51.png
screenshot-actovision.dev-2024.02.12-19_17_46.png

here you can find my post type and custom fields . its still not working

#2683261

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

I can take a look. I'd appreciate it if you could give me the URL/User/Pass of your WordPress dashboard after you make sure that you have a backup of your website.
It is absolutely important that you give us a guarantee that you have a backup so if something happens you will have a point of restore.

Make sure you set the next reply as private.

I also need the name of the Form and the page you used the form in.

And Also where did you add the custom code so I can check.

Thanks.

The topic ‘[Closed] how to populet custom dropdown field with custom post titles?’ is closed to new replies.