I am trying to: asign a photograph to a post type father (“fotografo”)
Link to a page where the issue can be seen: its backend feature
I expected to see: assign a porhograph with a hidden field in a form, to a post type father called “fotografo”
Instead, I got: the title of the page that contains the form
A moth ago (perhaps something more) it worked correctly but with some update it broke. Please helpme
Regards
Hi, when Types 3.0 was released it included a major change to post relationships. The _wpcf_belongs_slug_id custom field method is no longer used to assign post relationships in the new system. If you updated and ran the post relationship migration tool, this could be why the post relationship assignment no longer works. May I ask if you ran the post relationship migration process on your site?
If so, we can remove this field and replace it with another field to assign the post relationship. To do that, I would start by creating a new Form with the same configurations as this Form. In other words, this Form should edit or create new Photograph posts. Then use the Auto-generate button to generate the code automatically. The post relationship field should be created automatically using the updated, correct code. You will copy that code and paste it into your other Form in place of the old cred generic field.
I can help if you have problems.
Hello, the problem was not resolved. I did what you said but the images are not assigned to any photographer.
I explain a little better:
1. There is a WordPress user
2. The WordPress user has a photographer profile created with "types".
3. WP users should be able to add photos to their photographer profile from a creed form with "types" but they are not AUTOMATICALLY assigned to the photographer belonging to their WP profile. On the contrary, there is a select field to select the photographer who owns that photo that we want to upload, but that is NOT WORTH because any user could upload photos to other photographer profiles.
2 months ago you could automatically assign the photographer with the image code but since the update you can no longer
Could you help me?
Hi, this ticket was somehow marked resolved and I didn't get notified of your recent post. I have reopened the ticket so we can continue working on this.
On the contrary, there is a select field to select the photographer who owns that photo that we want to upload, but that is NOT WORTH because any user could upload photos to other photographer profiles.
You can use a shortcode to set the value of the new post relationship field automatically, and hide the field, so your Users cannot change it. Or, you can keep the existing generic field and add some custom code that sets the post relationship on the backend when the Form is submitted. Which would you prefer? I can help with either one.
Hi,
I prefer to use a shortcode to set the value of the new publication relation field automatically and hide the field.
I've tried with this:
<div class="none">
[cred_field field='_wpcf_belongs_fotografo_id' class='form-control' output='bootstrap' select_text='--- not set ---' author='$current']
</div>
But it dont works. (class="none" means display:none;)
Please help me.
I see you are using the "author" attribute and $current:
[cred_field field='_wpcf_belongs_fotografo_id' class='form-control' output='bootstrap' select_text='--- not set ---' author='$current']
The attribute should be "value", not author. The value of the value attribute should be [wpv-post-id] like it was before in the generic field:
[cred_field field='_wpcf_belongs_fotografo_id' class='form-control' output='bootstrap' select_text='--- not set ---' value='[wpv-post-id]']
If this isn't working as expected, I will be glad to log in and take a closer look. Please provide login credentials in the private reply fields here.
I just logged in and visited this URL:
enlace oculto
In the "My photos" tab, I clicked a link to "Add a photo". I am redirected to this URL:
enlace oculto
There is an error on this page. If you open the console you can see
Uncaught SyntaxError: Unexpected identifier...index:584
If you look at the page source, you can see this code written out:
<script type='text/javascript' class='custom-js'>
add_shortcode('my_parent','my_parent');
function my_parent($atts, $content)
{
global $post;
return $post->ID;
}
</script>
There is PHP code written out in the Form's custom JavaScript area, which is causing a JavaScript error. This "my_parent" shortcode definition should be moved out of custom JavaScript and into a custom PHP snippet. I have commented this code out for now.
Next, I can see now that Fotografo is a custom post type. Each User has one Fotografo post, and they are the author of that post. So to relate a Foto to a Fotografo, you need to know the Fotografo ID for the current User's Fotografo post. It looks like there was a View created for this purpose:
enlace oculto
I edited this View to disable the wrapping div, and inserted the View in the cred_field shortcode:
[cred_field field='_wpcf_belongs_fotografo_id' class='form-control' select_text='Choose your photographer' output='bootstrap' type="hidden" value='[wpv-view name="fotografo-de-este-usuario-en-add-foto"]']
Now the correct Fotografo is selected (Tomy) when I visit this add-foto page. Can you take a look and let me know if it's working more like you expect now?
Thank you, thank you, thank you Christian.
Now everything works perfectly.
I have understood the solution you have proposed and will apply it in future forms.
Thank you very much for your patience and for your way of explaining things.
It's been a pleasure 😉
My issue is resolved now. Thank you!