Skip Navigation

[Resolved] Custom post join with a product

This support ticket is created 7 years, 1 month ago. 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.

Our next available supporter will start replying to tickets in about 1.66 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 7 replies, has 2 voices.

Last updated by Noman 7 years, 1 month ago.

Assisted by: Noman.

Author
Posts
#571301

Hi,
I have a cred post form where you create a post that is showing in my website via layout.
I want to know if I can create another cred form with Woocommerce product and this product can be join to the previous custom post.
For example:
I have a post created with my cred form. This post can be see it in my website with a layout.
But I want to buy something inside this layout. A product. But this product is created by the same user that created the custom post. And I use the shortcode [add_to_cart id="62729"] where the "id" it has to be the product "id" join with the custom post.
There is a way????

#571390

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Oriol,

Thank you for contacting Toolset support. You need to create relationship between CPT and Product. See attached screenshot.

After that you need to create CRED child form. Please check here this is what possible for post relationship CRED forms: https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

Thank you

#572010

Ok. I follow your indications and almost all is ok. But I have a problem,
I need to edit in front end this 'child' product.
When I do it, it appears all the products but I just want to edit the product created by the user whom creates the parent add.
Now I have an users backend where they can add, delete an view their posts (adds). Now I'm trying to add the product edition in this backend.
I use a view to show the edit product form but I can't find the link parameter to edit just the user product.
There is a way?

#572075

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Post author filter.png

Hello,

Great that you were able to achieve some results. To put author restriction on it, you can try adding "Post author filter" in your View -- see attached screenshot.
Here is doc for this filter: https://toolset.com/documentation/user-guides/filtering-views-query-by-author/

If above does not solve the issue, please provide temporary access (WP-Admin and FTP Login info) to your site (preferably staging site), so that I can look into your setup and check the issue.

Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please provide link to the Page link, View Edit Screen link, CRED form edit link.

Thank you

#574177

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for providing login info. But I also requested for page link and other info, please provide the Page link, View Edit Screen link, CRED form edit link.

When I do it, it appears all the products but I just want to edit the product created by the user whom creates the parent add.
==> Please kindly provide page link.

Right now I have no idea where this issue occurs and which CRED form or View is involved in your site so its not possible for me to check without this info.

Thank you

#574364

As I said in the last post my problem not is in the edit form. My problem is in the creation of the new post form.

The page is: hidden link.

First I create an add (hidden link) and then I want to join the product to this add.

I have to use to set parent post cred field _wpcf_belongs_{$parent_slug}_id but I just want to show only the posts created by the user active that moment, not all the posts.
I tried with views as you tell me, but nothing happens. The view doesn't filter child fields. And I returned to insert the cred directly in the page.
There is a way?
I found that topic: https://toolset.com/forums/topic/automatically-set-parent-_wpcf_belongs_parent_slug_id/ but there is not the final solution....

#574430

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for providing more details. I am working on this further and will update you with my findings soon.

Thank you for waiting on this.

#574471

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

I have made some updates please check:
hidden link

Child posts are here: hidden link

1. I have created Custom select & shortcode with this code:

/**** Create custom shortcode [current_user_parent_post_select] ****/
function current_user_parent_post_select_func(){
    $current_user = wp_get_current_user();
    $userid = $current_user->ID;
 
    $args = array(
        'post_type' => 'event-indiv-premium', // parent post slug
        'author' => $userid,
        'nopaging' => true
    );
    // Return an array of all posts of current user
    $user_posts_list = get_posts($args);
 	
	$content = '<select name="event_parent" class="form-control" output="bootstrap" required="required">';
			$content .= '<option>--- Choose your add ---</option>';
			foreach ($user_posts_list as $post) :
				$content .='<option value=' . $post->ID . '>' . $post->post_name . '</option>';
			endforeach;
	$content .='</select>';
	wp_reset_postdata();
	return $content;
}
add_shortcode( 'current_user_parent_post_select', 'current_user_parent_post_select_func' );

2. After that I added the shortcode in the form:

[current_user_parent_post_select]

3. Then saved parent ID on form submit using cred_save_data hook and this code:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

add_action('cred_save_data', 'prefix_product_cred_save_data_action', 10, 2);
function prefix_product_cred_save_data_action( $post_id, $form_data ){
    if ($form_data['id']==62893){ //do the following code only if the CRED form ID is 62893, adjust this to your CRED form ID
        if (!empty($_POST['event_parent'])){ //if parent is selected
            $parent_id = $_POST['event_parent'];
            add_post_meta($post_id, '_wpcf_belongs_event-indiv-premium_id', $parent_id, true); //save the ID of the event as parent of the current post
        }
    }
}

I hope its good now, Thank you