Skip Navigation

[Resolved] Connect "Company" to "company offer" via Front-end

This support ticket is created 6 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Christian Cox 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1121489

I have now changed the filter from Another to Post relationship, and of course did that work as Chritian Cox said. (#1120994) 🙂
This is now working when im adding the company from back-end to the offer (posttype : CompanyOffer)

Now i like the Front-end to work as well.
The flow:
A user can register and loggin (this step works) .
The user is then loggin in. (also works)
The user can also create a company (posttype; company) (this works)

But when the user stands on the company page (my content) and tries to add a offer, this is not connecting to that company the user created.

How do i connect this from frontend so the users can add this by them selfs so no admin need to do this connection. I cant find any "hidden fields" that can bring the company-identifier or somthing likte that to identify the company to connect the company the user owns to the offer that the company owns.

#1122377
menu.png

But when the user stands on the company page (my content) and tries to add a offer, this is not connecting to that company the user created.
I can see that you have a One-to-Many Relationship between Companies (one) and Company Offers (many). I can see that you have created a New Offer Form here: hidden link
This Form does not include a Post Relationship field, so no connection is made between the Company and the Offer. You can add the Post Relationship field and allow your Users to select from a list of Companies (see the screenshot), or I can help provide some custom code that connects to the User's only Company automatically.

Selecting from a list of Companies is best if Users can be related to more than one Company. If a User can only be related to one Company, then custom code automation is probably best. Which do you prefer? I cannot recall from the previous tickets if Users can be related to more than one Company.

#1122579

Thanks you for your answer! I hope you had a great weekend!

Its not a good solution to allow the user to select company from a list.
The users may only be connected to the company he/she is the owner of. Only One company.
So i would love som custom code so this step is automated so the user is automaticly connected to the company
the user has added. But this step works!
The user is connected to the company-info.
What not working is the "Company offer" situation.

This is the first step for a user;
Flow:
1. user register
2. user login (i hop this can be automated later)
3. User register his/her company
4. landing on the company content info page (my content)
5. Adds offers via button (THIS Step not connecting the offer to the company)

This is the step for a registered user:
Flow 2:
1. Already registered user login
2. landing on his/her company content page
3. Adding Offers via button "add offer" (THIS Step not connecting the offer to the company)

#1122966

Here's a custom code snippet that will connect the new Offer with the current User's Company. You can add this in your child theme's functions.php file, or you can create a new snippet in Toolset > Settings > Custom Code.

add_action('cred_save_data', 'ts_connect_new_offer_to_existing_company',10,2);
function ts_connect_new_offer_to_existing_company($post_id, $form_data)
{
  // if a specific form
  $forms = array( 2877 );
  if ( in_array( $form_data['id'], $forms ) )
  {
    // get the current user's company post
    $company_args = array(
      'post_type' => 'company',
      'author' => get_current_user_id(),
      'posts_per_page' => 1,
    );
    $companies = new WP_Query($company_args);
    $company = isset( $companies->posts[0] ) ? $companies->posts[0] : null;

    // connect the new offer with the company using the post relationships api
    $connection = isset( $company->ID ) ? toolset_connect_posts( 'company-offers', $company->ID, $post_id ) : null;
  }
}

*edit - I had the wrong relationship name in the toolset_connect_posts call, so I fixed that.

#1123500

Thank you, it works!

But the snipplewt does someting with this permalink
hidden link

i landing on "blog", before i landed correct on the page named "Registrera"

#1123888

I don't think it's the snippet, because the snippet is currently inactive. I re-saved your site Permalinks (wp-admin > Settings > Permalinks) and now it seems to be showing the correct page. Can you confirm?