Skip Navigation

[Resolved] Can I create a post relationship and only use it conditionally?

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.

This topic contains 25 replies, has 3 voices.

Last updated by himanshuS 1 month, 1 week ago.

Assigned support staff: Shane.

Author
Posts
#2159227

I have a post type called Projects.

Projects can be created by three user types - professionals, experts, and employers. The first two can create standalone projects to share their work. But, employers can only create projects related to a job CPT.

A Jobs CPT and Projects CPT need to be a M2M relationship - but only get activated when an employer is creating a project. In other words, can I make it mandatory for a project to have a relationship with a job only if it is created by employers?

This could be solved by making the post-relationship field not mandatory for professionals and experts but mandatory for just employers.

Can this be done?

#2159851

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Do users edit content in the back end or the front end?

There is no provision to modify the relationships UI in the back end where you could intervene to disable the UI to connect posts.

If they add content from the front end, you would need to use a Relationship form to connect the posts.

Access doesn't offer role-based permissions for Relationship forms in the same way it does for normal post forms, but it should be possible to either use Access shortcodes or a Conditional Block to only insert the links to the relationship form for certain roles, so that other roles do not see them.

Does that sounds like a feasible route to go down?

#2163027

That works Nigel. Thanks.

#2163073

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

HI Himanshu,

It would appear that Nigel was able to assist you with resolving this.

If there are no further queries on this then you can go ahead and mark this as resolved.

Thanks,
Shane

#2163177

I used a slightly different solution to make it work. This solution is based on previous support I got from the Toolset team.

1) Create a generic multiselect field in CRED form to post projects
2) Create a view to populate that filed with job ids for jobs created by the current user
3) Insert that view in the generic field.
4) Run custom code to connect posts in m-2-m relationship.

This has worked for me in anotehr scenario and I think it will work here too but I am coming across a small problem.

Problem - the multi-select field is not populated with the information from the view BUT when I add the view as standalone to the form it shows the JSON data. The data is visible without access shortcode. So it has to do with access control but I am not sure hwo to grant access to a generic field to a user.

Here is the code that does not work --

[toolset_access role="employer" operator="allow"]
<div class="form-group job-post-form-group">
		<label>[cred_i18n name='job-post-label']Select Job(s) (use command or ctrl key to select more than one job)[/cred_i18n]<span class="red-color">*</span></label>
       [cred_generic_field type='multiselect' field='job-post']
	 {
	 "required":1,
	 "options":[ [wpv-view name="job-posts-dropdown-for-project-prompt"] ]
      }
	 [/cred_generic_field]  
 </div>
[/toolset_access]

Here is the code that works -

<div class="form-group job-post-form-group">
		<label>[cred_i18n name='job-post-label']Select Job(s) (use command or ctrl key to select more than one job)[/cred_i18n]<span class="red-color">*</span></label>
       [cred_generic_field type='multiselect' field='job-post']
	 {
	 "required":1,
	 "options":[ [wpv-view name="job-posts-dropdown-for-project-prompt"] ]
      }
	 [/cred_generic_field]  
 </div>
#2163863
#2163873

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Himanshu,

Perhaps we can workaround the issue by using our Toolset Conditional shortcode rather than the access shortcode to hide the field.

[wpv–conditional if="('[wpv-current-user info='role']' eq 'employer')"]
<div class="form-group job-post-form-group">
        <label>[cred_i18n name='job-post-label']Select Job(s) (use command or ctrl key to select more than one job)[/cred_i18n]<span class="red-color">*</span></label>
       [cred_generic_field type='multiselect' field='job-post']
     {
     "required":1,
     "options":[ [wpv-view name="job-posts-dropdown-for-project-prompt"] ]
      }
     [/cred_generic_field]  
 </div>
[/wpv–conditional]

Please let me know if it works like this.

Thanks,
Shane

#2163885

Shane,

The conditional does not seem to work. The field is visible for all user types. -

Non-employer user without a job post - hidden link

Employer type user with a job post - hidden link

#2164601

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Himanshu,

It would appear that the conditional shortcode itself isn't rendering. Though i'm not seeing any immediate issue with the shortcode itself. It appears to be correct.

Would it be possible to get admin access to the page as well as the form so that I can have a more detailed look at this one for you ?

I've enabled the private fields for your next response.

Thanks,
Shane

#2165021

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Himanshu,

Your toolset plugins need updating. Can you perform the update at the link below and let me know if the problem still persists.
hidden link

The latest versions may have fixed the issue.

Thanks,
Shane

#2165139

Shane,

I just checked and I am afraid the issue still exists.

link - hidden link

Regards,
Himanshu

#2165845

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Himanshu,

Without doing too much testing I was able to see that the issue is still replicable even on a test page and a test form that I created.
hidden link

This indicates to me that there is some conflict somewhere that is preventing the shortcode from rendering as this issue doesn't occur on a fresh install.

Even on a simple post the conditional tags do not render.

If possible can you disable all the non-toolset plugins and check the test page to see if the shortcodes for the conditional start working. If not then I will need to take a copy of the site so that I can test it locally here.

Thanks,
Shane

#2165883

What if I give you a staging site where you can do whatever you want? Will that work?

#2166007

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Himanshu,

Yes this will work.

I've enabled the private fields once more.

Thanks,
Shane

#2168279

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Himanshu,

I've taken a copy of the staging site to check here locally as in my testing the shortcode still doesn't render.

Hopefully we can provide a solution to this soon.

Thanks,
Shane