Hello
I have books that the user can select
hidden link
perhaps with an select button
I have a publication form,
hidden link
in the area with the word processor (or another one)
I would like to list the custom fields (title, author, price) of the books selected by the user.
What is the right way to do this
guy
to try to be more precise
Each time a book is selected (select button on the book pages), these three fields are sent to create an article with a list that is filled in successively with the three fields of the selected books. And it is this document that is sent.
guy
Hello guy and thank you for contacting the Toolset support.
If I understood well, you will need to create a relationship(one-to-many) from "Livre" post type to the post type of the form "bon-de-commande". And you need to have the parent post(livre) preselected in the form. Check this section of this article https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/#creating-forms-when-a-parent-post-is-preselected
The parent post will be passed using a URL parameter, you will need to build a shortcode that will pull the post's fields(title, author, price) based on the URL parameter. Then, pass it to the field value:
[cred_field field='post_content' value='[the-custom-shortcode]']
Check this article https://toolset.com/documentation/adding-custom-code/how-to-create-a-custom-shortcode/
I hope this helps. Let me know if you have any questions.
Jamal
I created relationnship(one to many) between book and order form.
I created the button(sélectionner ce livre) that opens the order form (with the parent link)
hidden link
But I have a lot of trouble with the creation of the shortcode.
here are the three fields I want to send to fill in the order form
[wpv-post-field name="wpcf-wpv-post-title"]
[wpv-post-field name="wpcf-wpv-book-price"]
[wpv-post-field name="wpcf-wpv-post-link"]
in a view that looks for the names of the artists
can you help me to formulate it?
thanks
guy
I'll suggest that you use a content template to build this content. Create a content template and add the fields to it. Then add the following code to a snippet in Toolset->Settings->Custom Code or to your theme's functions.php adapt line 8 to use the name or slug of your content template.
// Add Shortcode
function myprefix_book_order_content_template_func( $atts ) {
// get the book ID from the URL
$book_id = isset( $_GET['parent_page_id'] ) ? $_GET['parent_page_id'] : "";
if ( empty( $book_id ) )
return "";
return do_shortcode('[wpv-post-body view_template="name or slug of the content template" item="' . $book_id . '"]');
}
add_shortcode( 'book-order-content-template', 'myprefix_book_order_content_template_func' );
This code will render the content template for the book_id that was passed in the item attribute. Read more about it here https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/
If you still encounter an issue with this, please allow me temporary access to your website to check it further. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
I forgot to add the code of the form:
[cred_field field='post_content' value='[book-order-content-template]']
The code snippet was not activated yet. hidden link
To add the shortcode to the form field, you need to switch to expert mode hidden link hidden link
And it seems that the child form link was not added correctly, because it generates a URL that points to the "Bon de Commande" page as a parent instead of the Livre. But I am unable to update it. hidden link
Probably because we are both editing the same content template. I'll let you remove that block, save the content template, then add it again.
Let me know if it still does not work.
Hello Jamal
It still doesn't work.
I'm leaving the site's admin for the moment
thank you
guy
Hello guy, finally the content template updates the link correctly.
But, you have actually entered the shortcode not correctly(cred_field inside cred_field). Instead of:
[cred_field field='post_content' output='bootstrap' value='[cred_field field='post_content' value='[book-order-content-template]']']
Use:
[cred_field field='post_content' output='bootstrap' value='[book-order-content-template]']
The shortcode also needed to be updated, because, now, the generated URL uses "parent_livre_id" instead of "parent_page_id".
function myprefix_book_order_content_template_func( $atts ) {
// get the book ID from the URL
$book_id = isset( $_GET['parent_livre_id'] ) ? $_GET['parent_livre_id'] : "";
if ( empty( $book_id ) )
return "";
return do_shortcode('[wpv-post-body view_template="champs-pour-la-commande" item="' . $book_id . '"]');
}
add_shortcode( 'book-order-content-template', 'myprefix_book_order_content_template_func' );
I fixed all this for you. Check the results hidden link
Jamal,
It's good when I work with the admin open, but not when it's closed.
On the other hand, in my initial request, I asked for a list of several books.
Do you think it's possible?
guy
Hello guy,
What do you mean by this? It's good when I work with the admin open, but not when it's closed.
On the other hand, in my initial request, I asked for a list of several books.
Theoretically, it is possible. But, it will need a different relationship, One-to-many from the "Commande" to the "Livre". But, you will have to choose each book inside of the "commande" form. Or you need to implement custom code to store each selected book in the session, similarly to how WooCommerce implements the Cart feature. I belive it would be heavy on term of custom code, so, you will need to hire a developer for it.
Let me know if you want to implement the first option, using the reversed relationship, and, as I explained, you need to choose the book in the Commande form, not on the book page.
Hi Jamal
This is what I get when I select a book (see picture). This is what I don't understand.
And the first option suits me very well, if I understand how it works.
thank you
guy