Navigation überspringen

[Gelöst] Dynamic Field values from CPT

This support ticket is created vor 4 Jahren, 4 Monaten. 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 9 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von larryL vor 4 Jahren, 4 Monaten.

Assistiert von: Minesh.

Author
Artikel
#1744831

I added a second post form and attempted to add an additional function:


        break;
    }
    return $options;
}

// Dynamic title for cameras


add_filter( 'wpt_field_options2', 'func_to_dynamically_populate_camera_locations', 10, 3);
function func_to_dynamically_populate_camera_locations( $options, $title, $type ){
    switch( $title ){
        case 'Camera Title':
            $options = array();
  

to provide a select field to pull the titles from the 'cameras' CPT into the CRED form. But it's not working. I added a 'camera title' select field to the form and added


jQuery(document).ready(function() {
    jQuery('select[name="wpcf-tmna-location-title"]').toolset_select2();
    jQuery('select[name="wpcf-camera-title"]').toolset_select2();
});

which also broke the previous function/field that was already working.

What am I doing wrong?
(see https://toolset.com/forums/topic/pass-value-to-number-field-in-cred/)

Thanks

#1744941

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

The hook name to fill the dynamic option to the Types select field is wpt_field_options and you are using the hook wpt_field_options2 which is not correct.

you will require to use the hook wpt_field_options and change the function name to something else but I hope and consider here that you already created select field using Types.

More info:
=> https://toolset.com/documentation/programmer-reference/types-api-filters/#wpt_field_options

#1750437

I'm not seeing what you are seeing. And all the information that was there is now missing.

1 - Field data that had been displayed (location information) is now missing.

2 - I cannot figure out why it's broken.

3 - I've tried all sorts of things but I'm completely lost. Please review the previous ticket so you know what I'm talking about.

Thanks!

#1753201

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Can you please share problem URL and access details and share what form you are using and what content you want to display with your location field.

Also, please share what thing is broken and not working. Once I get the information and review the things I will be able to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1753511

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

When I loggedin to your site and checked the view - I see that your view is set to display the CPT " vehicles".

Now, When I edit any single "vehicles" post - I see there is a field available "TMNA Location" and that field is a textbox and not having any content.
=> versteckter Link

Also, I see that the same field "TMNA Location" is also available with CPT 'TMNA Location' and again it's a text field instead of the select field.

Have you made any changes to your site as well as I would like to know - did you created select field or text field? From what post type (vehicles OR TMNA Locatio) you want to display the field value. As for now, I do not see any select box for TMNA Location field.

In addition to that, where you added the custom code with the filter "wpt_field_options2"?

#1757371

The only changes I've made since we talked in the previous ticket were on other CPTs. But for the sake of this issue I'll re-iterate what I'm trying to do from the beginning:

From within the 'vehicles' CPT I need to beable to select post-titles from TMNA-locations and save them to vehicle-locations custom field. I also need to do this same thing from other CPTs For example, from the 'kanbans' CPT, I also need to be able to select post-titles from the TMNA-locations and save them to the vehicle-locations custom field (and so on). This was working before. The data was there, and the views was also working.

Does this help?

Thanks!

#1757379

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Have you checked the post-reference field?

If you add a post reference field to your custom field group - it will allow you to add a field where you can select the post title.
=> https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/using-post-reference-fields-to-display-information-from-a-related-post/

The post referenct field will allow you to connect your post type X with another post type Y. Can you please check if this solution suits you.

#1757547

That isn't the whole problem tho. The first issue is that the data that was written to the vehicle-location field is missing. So there has to be something wrong with the function? The view component of this is secondary.

#1757629

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

The first issue is that the data that was written to the vehicle-location field is missing.
==>
That is what I'm saying that why the data is missing. What changes you made to the side so that those field values are missing even you say you have a dropdown and I do not see any dropdown while I edit your post.

So there has to be something wrong with the function? The view component of this is secondary.
==>
Where you added the function? where I can find the function and to what field that function you have applied?
Where you added the code that you shared with your initial post?

#1758661

My issue is resolved now. Thank you!