Skip Navigation

[Resolved] Showing Parent Slug in Custom Query

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

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
- 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+00:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 6 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#594159
pm1.PNG
pm2.PNG

Hi. I'm opening up this "mess" to see if we can get it to work! I'ved worked with Beda on this ticket:
[Closed] Displaying Custom Fields in Search Results in a Many to Many setup opened on July 18, 2017

I've built a query page for my client (hidden link) where we want to see a list of machines (custom post types) filtered by the content in custom fields. As you can see in the attached screen shot in PM1.png, all the data shows except the company name and the ownership type. In screenshot PM2.png, you can see the Loop code in the view. i've made changes and redone it so many times but it still isn't working.

This is a many to many relationship. Companies are parents. Contacts are children. Ownership are children. Products (machine) are parents. Ownership are children of the Machines. Each machine is owned by a company, hence the query.

here's my view code

[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group">
	<label>[wpml-string context="wpv-views"]Type any part of the Machine Title[/wpml-string]</label>[wpv-filter-search-box output="bootstrap"]
</div>
<div class="row">
	<div class="col-sm-8"><div class="form-group">
	<label>[wpml-string context="wpv-views"]Product categories (in Inventory Quantity Order)[/wpml-string]</label>[wpv-control-post-taxonomy taxonomy="product_cat" type="checkboxes" orderby="count" order="DESC" url_param="wpv-product_cat"]
      </div></div>
	<div class="col-sm-4"><div class="form-group">
      <div class="form-group">
	<label>[wpml-string context="wpv-views"]Machine Number[/wpml-string]</label>[wpv-control-postmeta field="_sku" type="textfield" url_param="wpv-_sku"]
</div>
	<label>[wpml-string context="wpv-views"]Year Manufactured[/wpml-string]</label>[wpv-control-postmeta field="wpcf-pm-year-machine-manufactured" url_param="wpv-wpcf-pm-year-machine-manufactured"]</div>
  <div class="form-group">
	<label>[wpml-string context="wpv-views"]Machine Size A (number)[/wpml-string]</label>[wpv-control-postmeta field="wpcf-pm-machine-size-a" url_param="wpv-wpcf-pm-machine-size-a"]
</div>
      <hr>
      <div class="form-group">
	<label>[wpml-string context="wpv-views"]Expected Quote Price Min[/wpml-string]</label>[wpv-control-postmeta field="_price" type="textfield" url_param="wpv-_price_min"]
</div>
<div class="form-group">
	<label>[wpml-string context="wpv-views"]Expected Quote Price Max[/wpml-string]</label>[wpv-control-postmeta field="_price" type="textfield" url_param="wpv-_price_max"]
</div>
      <hr>
      <div class="form-group">
	<label>[wpml-string context="wpv-views"]Machine Asking Price Min[/wpml-string]</label>[wpv-control-postmeta field="wpcf-pm-machine-asking-price" url_param="wpv-wpcf-pm-machine-asking-price_min"]
</div>
<div class="form-group">
	<label>[wpml-string context="wpv-views"]Machine Asking Price Max[/wpml-string]</label>[wpv-control-postmeta field="wpcf-pm-machine-asking-price" url_param="wpv-wpcf-pm-machine-asking-price_max"]
</div>
  </div></div>
[wpv-filter-submit name="Search" type="button" output="bootstrap" class="btn-primary"]     [wpv-filter-reset type="button" output="bootstrap" class="btn-primary"]

[/wpv-filter-controls]
[wpv-filter-end]

Here's the output

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<table width="100%" class="table table-striped">
		<thead>
			<tr>
				<th>[wpv-heading name=""][/wpv-heading]</th>
				<th>[wpv-heading name="post-link"]Machine Name[/wpv-heading]</th>
				<th>[wpv-heading name="post-field-_sku"]Machine Number[/wpv-heading]</th>
				<th>[wpv-heading name=""]Category[/wpv-heading]</th>
				<th>[wpv-heading name=""]Expected Quote Price[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-pm-machine-asking-price"]Asking Price[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-pm-machine-size-a"]Machine Size A[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-pm-machine-size-b"]Machine Size B[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-pm-machine-size-c"]Machine Size C[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-pm-machine-size-d"]Machine Size D[/wpv-heading]</th>
				<th>[wpv-heading name="post-field-company_name"]Company[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-pm-machine-ownership-type"]Ownership Type[/wpv-heading]</th>
			</tr>
		</thead>
		<tbody class="wpv-loop js-wpv-loop">
		<wpv-loop>
			<tr>
				[wpv-post-body view_template="Loop item in Machine Search v10"]
			</tr>
		</wpv-loop>
		</tbody>
	</table>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

here's the loop

<td>[wpv-woo-product-image]</td>
<td>[wpv-post-link]</td>
<td>[wpv-post-field name="_sku"]</td>
<td>[wpv-post-taxonomy type="product_cat" separator=", " format="link" show="name" order="asc"]</td>
<td>Sell Price:[wpv-woo-product-price]</td>
<td>[types field='pm-machine-asking-price' format='Asking Price: FIELD_VALUE'][/types]</td>
<td>A:[types field='pm-machine-size-a'][/types]</td>
<td>B:[types field='pm-machine-size-b'][/types]</td>
<td>C:[types field='pm-machine-size-c'][/types]</td>
<td>D:[types field='pm-machine-size-d'][/types]</td>
<td>[types field='field-slug' id="$parent_post_type_slug"][/types]</td>
<td>[types field='pm-machine-ownership-type'  option='wpcf-fields-radio-option-30c70fd68712f7ddd5e88d67d0358462-1']Owned[/types] [types field='pm-machine-ownership-type'  option='wpcf-fields-radio-option-498f77ad1d868d1b7d01e44cf0333bdf-1']Shared[/types] [types field='pm-machine-ownership-type'  option='wpcf-fields-radio-option-203a4c99391d84b4360b6d75aceea01e-1']Brokerage[/types] </td>

Any ideas? Thanks!

#594245

Nigel
Supporter

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

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

Hi Mike

From your question it looks like your many-to-many relationship looks like this:

Companies      Machines
      \         /
       \       /
       Ownership

Your View is querying and displaying Machines.

You want to output content about the linked Company.

Your problem is that the information about post relationships is stored on the child, so the linking Ownership post knows which Company owns which Machine, but the Machine knows nothing about the relationship and the Company knows nothing about the relationship. You can go up to grab fields from the parents, not down to get them from the child.

The solution here is that you need to add a nested View where you want to output the company info.

So you create a View which returns Ownership posts that has a post relationship filter to show ownership posts that are children of the current machine. Then in the Loop Output section of this View, that is where you can use the id attribute to output fields not from the ownership post but from the parent Company.

You then insert that View in the Loop Output section of your original View where you want the company field to appear.