Skip Navigation

[Resolved] Create page with parent post details followed by table of all child post details

This support ticket is created 3 years, 7 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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+00:00)

This topic contains 32 replies, has 2 voices.

Last updated by davidm-13 3 years, 6 months ago.

Assisted by: Jamal.

Author
Posts
#1782381

Hi, Have a page (content template) displaying parent post details would like to append a View to this displaying a table of all child posts - this is a one to many relationship.
Would prefer to use toolset shortcodes and not the blocks editor.
An example code snippet of how to set this up would be appreciated.
Thanks for any help

#1782581

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello and thank you for contacting the Toolset support.

First, you will need to create a view that will display the table of child posts. The view needs to have a query filter on the relationship, related to the page where the view will be displayed. Check this screenshot hidden link

Use the loop wizard, on the view, to create a table of results. Check this screenshot hidden link

Then you can include the view inside of the content template with the following shortcode:

[wpv-view name="name or slug of the view"]

Read more about Toolset shortcodes here https://toolset.com/documentation/programmer-reference/views/views-shortcodes/

I hope this answers your question. Let me know if you have further questions.

#1782649
query-filter.JPG

Hi Jamal,
Thanks for your reply. I tried what you suggested but I'm receiving "no records found" even though the parent post has child posts.
This is a medicinal plants database, the parent posts are the (medicinal) Plants and the child posts are the Complaints they treat .
This is a one-to-many relationship.
I've attached the Query Filter.
Any idea what I'm doing wrong?
Thanks for any help

#1782977

Hi,
I would like to debug this View to see the sql query that's not returning any results but I'm not receiving any popup report or any indication that the debug mode is active.
I've enabled popups in my browser (Chrome) and Debug Mode in settings > Front End Content.
Any ideas?
Thanks

#1783057
debug-info.JPG

ok, took out problematic jquery from the view template and received the debug report, (but still no records) .
Attached here - didn't tell me very much - can you give me any pointers based on this.
Thanks

#1783255

Hi,
Making progress, appears that order by for the View needs to be Post ID, or Post Date and not custom field from the record. I need the wp-query output sorted in a specific order, how can I do that?
Thanks

#1783293

Hi,
I'm trying to display the output from this view - table of child posts - with the following:

<td class="only-first-system-cf">
  <span>[wpv-post-field name="wpcf-system-cf"]</span>
</td>
<td>
  [wpv-post-field name="wpcf-complaint-use-cf"]
</td>
<td>
  [wpv-post-taxonomy type="action-medicinal" format="name"]
</td>
<td>
  [types field="prep-admin"][/types]
    </td>
<td>
  [wpv-post-taxonomy type="part-used" format="name"]
</td>

All the <td> fields in the table are empty - the query returns 10 records I see 10 empty rows. How can I see the results of this query?
Thanks

#1784173

I'm trying to display parent details followed by a table of all of the children, can't make any sense of what's happening.
Need you to look at my site.
Thanks

#1785671

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

My apologies for the late reply, but I do not work on Sundays and Mondays.

To better assist you with this issue, I would like to get access to your backend area and check it closely. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

If you are not able to provide access to your website, I can create a test site on our platform and we'll work on it to find a solution. Let me know if you would prefer that.

#1786043

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

The view was configured to display "Plants" and Complaints, it should only display Complaints. Check this screenshot hidden link

Then, the content template was assigned to the Archive posts instead of the single posts, which means, it will be used to display the "Plants" in the "Plants" archive (/plants/) or in a taxonomy(assigned to Plants) archive. Check this screenshot hidden link

But, all this did not help. For some reason, the view is querying posts instead of "Complaints". I tried with a new content template and a new view and I am getting 10 posts on the results instead of the 24 Complaints linked to the Plant you shared.

To investigate this further, I'll need to take a copy of your website and work on it locally. Please let me know if I can install the Duplicator plugin and take a copy.

#1786143

Hi Jamal,
Any help is much appreciated. So yes do whatever you need.
In the process of trying to solve this I used this custom code:

<?php
/**
 * query for child posts (medical complaints) treated by the parent plant
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.
add_filter( 'wpv_filter_query', 'prefix_show_only_current_author', 99,3);
  
function prefix_show_only_current_author( $query_args,$view_setting,$view_id ) {
if($view_id == 8752){
$query_args = array(
    'post_type' => 'complaint',
    'numberposts' => -1,
    'meta_key' => 'wpcf-system-cf',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    'toolset_relationships' => array(
        'role' => 'child',
        'related_to' => get_the_ID(),
        'relationship' => 'plant-with-complaint-list'
    )
);
 
$query = new WP_Query( $query_args );
$child_posts = $query->posts;
  }
}  

But when I activate it, it causes the white screen on the front end.
Like to know what's wrong with the code.
Thanks for your help

#1786317

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

The following code is not correct, the filter function should return $query_args.

But, I think, that the issue came from your server setup. Probably a cache layer at the server level, or an object cache that is interfering with the views.
As soon as I built a copy of your website, the view has worked without issues. Check this screenshot hidden link
I did nothing but building the copy, and it worked without issues. Here is the resulted SQL query from the view debug popup:

SELECT   wps8_posts.* FROM wps8_posts  WHERE 1=1  AND wps8_posts.ID IN (17427,17428,17429,17430,17432,17433,17434,17435,17436,17437,17438,17439,17440,17441,17442,17443,17444,17445,17446,17447,17448,17449,17450,17431) AND wps8_posts.post_type = 'complaint' AND ((wps8_posts.post_status = 'publish' OR wps8_posts.post_status = 'private'))  ORDER BY wps8_posts.post_date ASC, wps8_posts.post_title ASC 

I suggest, you take the Duplicator copy and build it on your local computer to get the same results as me.

Then, you will have to reach to your hosting provider and ask them for help, there is something active on the website that is interfering with the Toolset view.

#1786379

Hi Jamal,
Thanks for sorting this out.
A couple of weeks ago I installed another site with my hosting provider that shares the MySQL database with this site - I was assured that it would be ok. Could this be the cause of the problem. If I remove/uninstall the second site would this remove the problem?
You say about the custom code "the filter function should return $query_args" I tried as you suggested but still get the white screen could you give me the exact code.
Thanks

#1786401

Can I upload the Duplicator copy to my hosting provider replacing the copy I have there via Cpanel?

#1786457

I see the tables connected to the other site according to the prefix. in PHPmyAdmin can I just drop these tables

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