Skip Navigation

[Resolved] View with relationship

This support ticket is created 3 years, 4 months 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.

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)

Tagged: 

This topic contains 36 replies, has 3 voices.

Last updated by avansisI-2 3 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1857841

Shane
Supporter

Languages: English (English )

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

Hello,

Structure it like this.


[wpv-conditional if="( $(wpcf-comprobante) eq '' )"]
[cred_form form="adjunto-bonos"]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-comprobante) ne '' )"]
[types field='comprobante'][/types]
[/wpv-conditional]

Please let me know if this helps.
Thanks,
Shane

#1857923

thank you shane,

but I put that in place of something?

because if I put it like that, it doesn't work

<td>[types field='nombre_campana' separator=', ' item='@campana-bonos-bono.parent'][/types]</td>
<td>[types field="referencia-del-bono"][/types]</td>
<td>[types field="fecha-de-creacion-del-bono"][/types]</td>
<td>[wpv-post-taxonomy type="estado"]</td>
<td>[types field='comprobante'][/types][cred_form form="adjunto-bonos"]</td>
<td>[wpv-view name="child-view"]</td>

[wpv-conditional if="( $(wpcf-comprobante) eq '' )"]
[cred_form form="adjunto-bonos"]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-comprobante) ne '' )"]
[types field='comprobante'][/types]
[/wpv-conditional]
#1857935

Shane
Supporter

Languages: English (English )

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

Hello,

I've added it to the correct place now.

It should be like this.

<td>[types field='nombre_campana' separator=', ' item='@campana-bonos-bono.parent'][/types]</td>
<td>[types field="referencia-del-bono"][/types]</td>
<td>[types field="fecha-de-creacion-del-bono"][/types]</td>
<td>[wpv-post-taxonomy type="estado"]</td>
<td>
[wpv-conditional if="( $(wpcf-comprobante) eq '' )"]
[cred_form form="adjunto-bonos"]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-comprobante) ne '' )"]
[types field='comprobante'][/types]
[/wpv-conditional]</td>
<td>[wpv-view name="child-view"]</td>


Thanks,
Shane

#1858085

Hi Shane,

I have only one question.

with this view you create an child-view to 'comercios' if it is select. Is it posible that If It havent assigned a 'comercio', the option to choose it from the view appears. (with a dropdown)

#1858089

Hi Shane,

I have only one question.

with this view you create an child-view to 'comercios' if it is select. Is it posible that If It havent assigned a 'comercio', the option to choose it from the view appears. (with a dropdown) in the custom type 'campaña_bonos' parent of coupons i have a taxiomy with 3 options, and only those businesses within that category that accept coupons should appear (accepting coupons is another taxionomy)

#1858553

I've set it up just like this one does:

//AÑADIR RELATIONSHIPS PRODUCTOS
add_action( 'rest_api_init', 'create_api_posts_meta_field' );
 
function create_api_posts_meta_field() {
    register_rest_field( 'productos', 'parent-page', array(
           'get_callback'    => 'get_parent_page_for_api',
           'schema'          => null,
        )
    );
}
 
function get_parent_page_for_api( $object ) {
    //get the id of the post object array
    $post_id = $object['id'];
    //return the post meta
    return toolset_get_related_post( $post_id, 'productos');
}

That's why I don't know what I'm doing wrong

#1859297

Shane
Supporter

Languages: English (English )

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

Hello,

This is possible, however how i suggest doing it is to check if the post has children. Ideally you can just create a new form with just the Child Post field and just add this form to the "No Items Found" section in the child view.

So what will happen is that instead of the column displaying "No Items Found" it will display the form to assign a child post.

Please let me know if this helps.
Thanks,
Shane

#1859465
Captura-de-pantalla-2020-11-27-a-las-20.48.30.jpg

sorry Shane I mixed up the consultations. What I need is what I discussed in the previous post.

with this view you create an child-view to 'comercios' if it is select. Is it posible that If It havent assigned a 'comercio', the option to choose it from the view appears. (with a dropdown) in the custom type 'campaña_bonos' parent of coupons i have a taxiomy with 3 options, and only those businesses within that category that accept coupons should appear (accepting coupons is another taxionomy)

#1859477

Shane
Supporter

Languages: English (English )

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

Hello,

I actually explained how to achieve this here.
https://toolset.com/forums/topic/view-with-relationship/page/2/#post-1859297

However it seems you want to filter the available coupons by taxonomies in the dropdown, which won't be possible in the post relationship for the form that you will be using.

It will instead list all the coupons and you pick one from the list.

I recommend duplicating your current edit form and adding the post relationship option field to the form then add it to the "No Items Found" section in your post.

Thanks,
Shane

#1859497

I think the problem is that I don't know how to use the child-view, could you give me an example?

#1861677

Hello, Shane is on vacation this week so I am looking at his tickets. It sounds like you need to accomplish two things:
1. You want to display a list of the child Comercios posts for each Bonos post in the Comercios column. This seems to be working as expected, as shown in the screenshot child-comercios-list-in-results.png
2. You want a way to assign a child Comercio post to each Bonos post in the list if no child Comercios exist for that parent Bonos post.
- To do this, you must create a Relationship Form for the Bonos - Comercios relationship. That Form will allow you to select from Comercios posts and assign those to a parent Bonos post.
- You must insert the Relationship Form shortcode inside the child Comercios View in the "No results found" section of the child View's loop editor. That will display the Relationship Form only if no child Comercios exist.
- Replace the text "No results found" in the View's loop editor:

[wpv-no-items-found]No results found[/wpv-no-items-found]

- Insert the Relationship Form shortcode instead of "No results found" text, like this:

[wpv-no-items-found][cred-relationship-form form='your-relationship-form-slug' parent_item='$current'][/wpv-no-items-found]

- Replace your-relationship-form-slug with the slug of the Relationship Form. You can find that in the Relationship Form editor.
- This will display a Relationship Form if no child Comercios exist for the current Bonos post. If you want to hide the parent Bonos select field, you can add custom CSS in the Relationship Form editor to hide it.

#1861981

HI Christian,

I replace with this, (last two lines) but doesnt work it.

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<table width="100%">
		<thead>
			<tr>
				<th>[wpv-heading name="types-field-nombre_campana"]Nombre de la campaña[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-referencia-del-bono"]Referencia del bono[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-fecha-de-creacion-del-bono"]Fecha de creación del bono[/wpv-heading]</th>
				<th>[wpv-heading name="post-taxonomy"]Estados[/wpv-heading]</th>
				<th>[types field='comprobante'][/types]</th>
				<th>[wpv-heading name="post-taxonomy"]Comercios[/wpv-heading]</th>
			</tr>
		</thead>
		<tbody class="wpv-loop js-wpv-loop">
		<wpv-loop>
			<tr>
				[wpv-post-body view_template="loop-item-in-listado-bonos-administrador"]
			</tr>
		</wpv-loop>
		</tbody>
	</table>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found][cred-relationship-form form='your-relationship-form-slug' parent_item='$current'][/wpv-no-items-found]
[wpv-layout-end]
#1861991

It looks like you copied the example code and pasted it in your View, but did not change the relationship form slug. That could be the problem. Did you create a Relationship Form to manage the Bonos - Comercios relationship yet? If not, that could be the problem too. You must create a Relationship Form in Toolset > Relationship Forms. Then, you must replace the example form slug in the cred-relationship-form shortcode. See my previous comment:
- Replace your-relationship-form-slug with the actual slug of the Relationship Form. You can find that in the Relationship Form editor.

#1861995

Sorry,
this is an update

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<table width="100%">
		<thead>
			<tr>
				<th>[wpv-heading name="types-field-nombre_campana"]Nombre de la campaña[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-referencia-del-bono"]Referencia del bono[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-fecha-de-creacion-del-bono"]Fecha de creación del bono[/wpv-heading]</th>
				<th>[wpv-heading name="post-taxonomy"]Estados[/wpv-heading]</th>
				<th>[types field='comprobante'][/types]</th>
				<th>[wpv-heading name="post-taxonomy"]Comercios[/wpv-heading]</th>
			</tr>
		</thead>
		<tbody class="wpv-loop js-wpv-loop">
		<wpv-loop>
			<tr>
				[wpv-post-body view_template="loop-item-in-listado-bonos-administrador"]
			</tr>
		</wpv-loop>
		</tbody>
	</table>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found][cred-relationship-form form='seleccion-comercios-bonos' parent_item='$current'][/wpv-no-items-found]
[wpv-layout-end]
#1862659

Perhaps you placed the Relationship Form shortcode in the Bonos View by mistake? The Relationship Form shortcode should be in the child Comercios View, because you want to display it when there are no child Comercios. Right now, I see "No items found", which indicates the Relationship Form shortcode is not in the correct location.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.