Skip Navigation

[Resuelto] Parent-Child post relationship

This support ticket is created hace 6 años, 2 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

Este tema contiene 5 respuestas, tiene 2 mensajes.

Última actualización por Nigel hace 6 años, 2 meses.

Asistido por: Nigel.

Autor
Mensajes
#618390
Booth Picture if Booth Name is deleted and replaced with company name field.PNG
Booth Picture if Company Field is deleted, but not the Booth Name field.png
Current Form.PNG
Career Fair Page (parent) and relationship with Booth (child).png

I am trying to:

Sorry if this is confusing/ if I do not explain this well. Let me know if any clarification is needed.

I had a developer make a form for me called "New Booth Form (ID: 3110)". When completed, the "Booth Name" field input becomes the post title for a template called "Single Booths" and shows under the "Registered Booth" section on the "Career Fair" template. "Single Booth" is the child of the post "Carer Fair".

I wanted to take out this field as well as a few others, and replace this "Booth Name" field with the "Company Name" field so that the user's input for company name takes the place of the "Booth Name" field while fulfilling its role. Users tended to put the same information in the "Booth Name" as the "Company Name" so I wanted to consolidate these fields under the a field titled "Company Name". Here is what the code looks originally looked like for the New Booth Form (ID: 3110):

[credform class='cred-form cred-keep-original']

	[cred_field field='form_messages' value='']

	<div class="cred-field cred-field-post_title">
		<label class="cred-label">
[wpml-string context='cred-form-New Booth Form-3110'' name='Booth Name']Booth Name[/wpml-string]
</label>
		[cred_field field='post_title' post='booth' value='' urlparam='']
	</div>

	<div class="cred-field cred-field-post_content">
		<label class="cred-label">
[wpml-string context='cred-form-New Booth Form-3110'' name='Booth Description']Booth Description[/wpml-string]
</label>
		[cred_field field='post_content' post='booth' value='' urlparam='']
	</div>

	<div class="cred-field cred-field-_featured_image">
		<label class="cred-label">
[wpml-string context='cred-form-New Booth Form-3110'' name='Featured Image']Featured Image[/wpml-string]
</label>
		[cred_field field='_featured_image' value='' urlparam='']
	</div>

	<div class="cred-group cred-group-Booth-fields">
		<div class='cred-header'><h3>[wpml-string context='cred-form-New Booth Form-3110'' name='Booth fields']Booth fields[/wpml-string]</h3></div>
<!--
        <div class="cred-field cred-field-company-name">
			<label class="cred-label">
[wpml-string context='cred-form-New Booth Form-3110'' name='Company Name']Company Name[/wpml-string]
</label>
			[cred_field field='company-name' post='booth' value='' urlparam='']
		</div> 
-->
		<div class="cred-field cred-field-your-company-name">
			<label class="cred-label">
[wpml-string context='cred-form-New Booth Form-3110'' name='Your Company Name']Your Company Name[/wpml-string]
</label>
			[cred_field field='your-company-name' post='booth' value='' urlparam='']
		</div>
      
      
		<div class="cred-field cred-field-jobsconnected-company-page-url">
          <div><strong>Instructions:</strong><br/> 
            1)-If you haven't created a job posting yet please <a href="<em><u>enlace oculto</u></em>" target="_blank">POST A JOB HERE!</a><br/> 
            2)-Please "COPY" the URL from the <a href="<em><u>enlace oculto</u></em>" target="_blank">Company Page (Click Here)</a> and "PASTE" the URL below. <br/>  </div>
			<label class="cred-label">
[wpml-string context='cred-form-New Booth Form-3110' name='JobsConnected Company Page URL']JobsConnected Company Page URL[/wpml-string]
</label>
			[cred_field field='jobsconnected-company-page-url' post='booth' value='' urlparam='']
		</div>

	</div>

	<div class="cred-group cred-group-parents" style="visibility:hidden">
      <div class="cred-field cred-field-_wpcf_belongs_fair_id">
			<label class="cred-label">
		[wpml-string context='cred-form-New Booth Form-3110' name='fair Parent']fair Parent[/wpml-string]
		</label>
			[cred_field field='_wpcf_belongs_fair_id' value='']
          
		</div>
		
	</div>

	[cred_field field='form_submit' value='Submit' urlparam='']

[/credform]

To do this, when editing the New Booth Form (ID: 3110), I replaced the

 <label class="cred-label">
[wpml-string context='cred-form-New Booth Form-3110'' name='Booth Name']Booth Name[/wpml-string]
</label>
		[cred_field field='post_title' post='booth' value='' urlparam=''] 

with the "Company Name" field

<div class="cred-field cred-field-your-company-name">
			<label class="cred-label">
[wpml-string context='cred-form-New Booth Form-3110'' name='Your Company Name']Your Company Name[/wpml-string]
</label>
			[cred_field field='your-company-name' post='booth' value='' urlparam='']
		</div>

. You can see the result in the image below. Basically, the form still works, but the title of the post on the child form "Single Booth" and parent post "Career Fair" says "CRED Auto Draft....." and a long string.

As a work around, I tried keeping the "Booth Name" field and simply making the text "Company Name", then the input no longer automatically shows a URL/Link under the "open positions" section of the "Single Booth" template, meaning that I have to do so in the back end. This is the case even if I change the code for the output of the "Single Booth" template.

The code for the "Single Booth" template is :

<div class='row'>
  <div class='col-md-8'>
    <strong>Booth Info:</strong><br/>
    [wpv-post-body view_template='None']
    [wpv-conditional if="( $(wpcf-anymeeting-com-booth-number) ne '' )"]
    <button>
      <a href='<em><u>enlace oculto</u></em> field="anymeeting-com-booth-number"][/types]'>AnyMeeting Booth Button</a>
    </button>
   
    [/wpv-conditional]
  </div>
  <div class='col-md-4'>
    <strong>Career Fair Page:</strong><br/>
    [wpv-post-link id='$fair']<br/>
    <strong>Open Positions:</strong><br/>
     [wpv-conditional if="( $(wpcf-company-name) ne '' )"]
    <a href="<em><u>enlace oculto</u></em> field="company-name"][/types]">[types field="company-name"][/types]</a>
    [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-your-company-name) ne '' ) AND ( $(wpcf-jobsconnected-company-page-url) ne '#' )"]
    <a href="[types field='jobsconnected-company-page-url' output='raw'][/types]">[types field='your-company-name'][/types]</a>
    [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-jobsconnected-company-page-url) eq '#' )"]    
    <p>[types field="company-name"][/types]</p>
    [/wpv-conditional]


  </div>
  
</div> 

[wpv-if evaluate="'[wpv-current-user info='id']' = '[wpv-post-author format='meta' meta='ID']' OR '[wpv-current-user info='role']' = 'administrator'"]
<div class='row'>
  <div class='col-md-6'>
    <button>
      [cred_link_form form='3111' form_name='Edit Booth Post' text='Edit %TITLE%' target='_self']
    </button>
  </div>
  <div class='col-md-6'>
    <button>
      [cred_delete_post_link class='cred-refresh-after-delete' text='Delete %TITLE%' message='Are you sure you want to delete this post?' message_after='Post deleted' message_show='0' action='trash']
    </button>
  </div>
</div>
[/wpv-if]

[php]

I tried changing anything with  [php]  [wpv-conditional if="( $(wpcf-company-name) ne '' )"]
    <a href="<em><u>enlace oculto</u></em> field="company-name"] 

to

   [wpv-conditional if="( $(wpcf-booth-name) ne '' )"]
    <a href="<em><u>enlace oculto</u></em> field="booth-name"] 

but that does not seem to fix the problem.

Link to a page where the issue can be seen: Need to be logged in as an admin or employer to see this page. I can provide credentials.

I expected to see:

Instead, I got:

#618610

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+01:00)

Hi Michael

Your form to publish a new booth post uses the post title field for the booth name.

A form should always set the post title, otherwise you end up with the auto-generated title you saw.

Your form also includes a custom field for company name. (Actually it contains two, but the first—'company-name'—is commented out, so only the second—'your-company-name'—will appear on the form.)

Your template "Single Booth" uses the company fields (to output their value subject to the conditional shortcodes confirming they have a value to output).

If you edit the form and change the label for the post-title field from the booth name to the company name that will solve the auto-generated title problem, but then means the company fields have no value to use in your template.

So you use the post title to generate the links.

But you are trying to use a field called "booth-name" when there is no such field. The field that stores the company name is the standard post title field, which is what you need to use. You can use it for output the name, but not the href of the link because it may contain spaces etc. For that you need the slug of the post title.

So you can use the wpv-post-title shortcode to output the title, and the wpv-post-slug shortcode to output the URL-friendly version, like so:

 <a href="<em><u>enlace oculto</u></em>">[wpv-post-title]</a>

I'm not sure what is required in terms of conditions here.

If this is on a template for a single booth, it will have a post title (the company name), and so there is no need to test if the post title is empty (which you were doing for the company fields previously).

#621072

Thank you very much. This makes a lot of sense.

First. I made a small change an altered your suggested code slightly to

 <a href="<em><u>enlace oculto</u></em>">Click here to view</a> 

as I realized that will make it easier for the users.

So after looking at the conditional statements, I believe that they were intended to do the following:

1.
Code:

 [wpv-conditional if="( $(wpcf-company-name) ne '' )"]
    <a href="<em><u>enlace oculto</u></em> field="company-name"][/types]">[types field="company-name"][/types]</a>
    [/wpv-conditional]

Intended Result: If the user inputs the company name, show the url under open positions.
Further Fixing Needed: None. After making the change that you suggested :

 <a href="<em><u>enlace oculto</u></em>">Click here to view</a> 

, this works as I need it to and there is no further editing required. The user will always fill out the company name section so this no longer needed to be coded as a condition.

***2.
Code:

 [wpv-conditional if="( $(wpcf-your-company-name) ne '' ) AND ( $(wpcf-jobsconnected-company-page-url) ne '#' )"]
    <a href="[types field='jobsconnected-company-page-url' output='raw'][/types]">[types field='your-company-name'][/types]</a>
    [/wpv-conditional]

Intended Result: If the user inputs a url in the "Company URL" field, then instead of using the href "enlace oculto;", the company's inputted url is used as the href.
***Further Fixing Needed: Not sure how to do this. Please advise.

3.

Code:

 [wpv-conditional if="( $(wpcf-jobsconnected-company-page-url) eq '#' )"]    
    <p>[types field="company-name"][/types]</p>
    [/wpv-conditional] 

Intended Result: If the user does not include the company name and does not include a url, the company name will display under the open positions header. I am not sure why the previous person put this in and does not seem to make any sense so I will remove this code.
Further Fixing Needed: None.

#621482

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+01:00)

Hi Michael

Sorry, I'm not sure I understand the continued relevance of #2.

If the users are submitting the form and entering the company name as the title, might they also be entering the company name as the your-company-name field?

If you want to output that field to use as part of a URL you would need to convert it to a URL-friendly format.

You would want to register a custom shortcode for the purpose and use the WordPress function sanitize_title which is used to convert post titles to slugs (https://codex.wordpress.org/Function_Reference/sanitize_title).

See https://developer.wordpress.org/plugins/shortcodes/ for details about creating shortcodes.

Is that what you are aiming to do? If you get stuck let me know.

#622648

Yes, that sounds like what I am aiming to do. I will give it a shot and will let you know if I get stuck. Thanks!

#622834

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+01:00)

Let me mark this as waiting to hear from you.

Good luck!

Este ticket ya está cerrado. Si eres cliente de Toolset y necesitas ayuda relacionada, abre un nuevo ticket de soporte.