[Resuelto] Adding relationship parent fields to form as checkboxes
This support ticket is created hace 4 años, 5 meses. 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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
Tell us what you are trying to do?
I have two custom post types that have a one to many relationship, I am using a new post form and I want to allow users to select a custom field from the parent ( in this instance a date), so far so good and it displays the correct select field.
For reasons (easier new post creation and easier editing of paid posts) I would like to allow a multi-select check box list which obviously doesn't work as it is a one to many, switching to a many to many losses the options for parent fields, and again and isn't what I want, as I will use a woocommerce hook to slit orders with multiple dates to create multiple posts with a single date.
I have tried "force_type" and "type" but they seem to get ignored.
Obviously I don't expect this to be a feature of toolset, but what are my options for inserting this into a form.
The only way I can think of is JS to rewrite the select to check boxes but I assume the validation will fail in all kinds of nasty ways?
Is there any documentation that you are following?
no
Is there a similar example that we can see?
no
What is the link to your site? enlace oculto
I'm a little confused by your thread. I'm not clear on what you want to achieve.
Here you said "I have two custom post types that have a one to many relationship". Where is this custom field? Is it on the Parent Post Type or the Child Post Type?
"I want to allow users to select a custom field from the parent ( in this instance a date)"
Are you referring to having a Parent Post field being added to the child post form when creating a child and getting its value from the parent field ?
" I would like to allow a multi-select check box list which obviously doesn't work as it is a one to many, switching to a many to many losses the options for parent fields, and again and isn't what I want, as I will use a woocommerce hook to slit orders with multiple dates to create multiple posts with a single date."
Here i'm not sure which field you are referring to, can you provide a screenshot on this and a little more details ?
Thanks for your time I will try to explain better.
In essence I have a frontend form for the custom post type "advert" that has custom fields "Date", "advert","name", "phone", etc.
In the form users needs to select one or multiple dates "publication dates" these publication dates need to be stored somewhere ( i thought a custom post type would work well but open to suggestions) as obviously I need to be able to set which dates are publication dates and which aren't.
I thought a custom post type "publication dates" with "date" and "issue number" custom fields would be the way to go.
I need to pull a list of available "publication dates""date" field into the advert form for front end users to select when they submit their advert.
All of this so far works with
[cred_field field='@publication-date-advert.parent' class='form-control' output='bootstrap' select_text='--- not set ---']
My primary issue right now is I need to allow users to select multiple dates and they often have the same advert in multiple publications. And with a select field they are limited to one.
Thank you for the clarity. I believe I have a better understanding now.
So instead of using a Date field itself you are using the Date as a Parent Post Type ie "Publications" and the child is essentially the "advert". So when you're creating an Advert you want the user to Select a Parent for that Advert.
So you want to the user to select Multiple Publications at the same time when they are creating the Adverts. Essentially this won't be possible to do on the frontend based on how the relationship works from the frontend.
Hi Shane,
As i said in my first post "I don't expect this to be a feature of toolset" but that doesn't solve my problem, I have to solve this one way or another, I just need help to find the most effective solution.
I would have expected this to work with the many-many relationships? have I missed something here?
My first step is how can I list the publications as checkboxes? The only way I can see (whilst utilising toolset) is for a custom shortcode? As the checkbox field I believe will take shortcode input.
The main problem is that on the frontend you won't be able to add multiple relationships at the same time on the frontend. This is a current limitation that we have.
Many to Many would be a good idea but because on the frontend this requires a Relationship form to connect the posts and you can only connect the posts one at a time.
If you are to go to the checkbox option you will essentially need to populate that checkbox with all the possible Parent post. This means gathering their ID's and Post title, then convert this list into a shortcode so that you can add it to a custom checkbox created on the frontend.
Once the form is submitted after you've setup this checkbox you will need to use our relationship hook to manually add each relationship with the hook by using the values from the checkbox field.
Unfortunately given the nature of this I won't be able to provide much assistance as this would require custom coding in order to pull all the posts that you want to appear in the checkbox.
However I hope i''m able to provide you with an alternative to think about.
Just going to add the shortcode details here for everyone else to enjoy.
function iseg_shortcode_publication_date(){
$args = array(
'post_type' => 'publication-date',
'posts_per_page' => '10',
'publish_status' => 'published',
);
$query = new WP_Query($args);
if($query->have_posts()) :
while($query->have_posts()) :
$query->the_post() ;
$postid = get_the_ID();
$my_meta = get_post_meta( get_the_ID() ,'wpcf-publication-date',true);
$result .= "{\"value\": \"" . $my_meta. "\", \"label\": \"" . date('d F Y', $my_meta) . "\"}, ";
// need to remove trailing ", " for this to work
endwhile;
wp_reset_postdata();
endif;
$result = substr_replace($result, '', -2); // to get rid of extra comma and space
return $result;
}
add_shortcode( 'publication-date-list', 'iseg_shortcode_publication_date' );
but I am having issue with the below not saving any data:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==85)
{
$sampledata = "99"
add_post_meta($post_id, 'wpcf-cost-total', $sampledata, true);
}
}
I've tried to slim is down best I can, this is trying to use just a number field to in case I was doing something wrong with dates etc. I've tried add and update