Skip Navigation

[Resolved] Limit view results by the parent post which is also the page’s parent post

This thread is resolved. Here is a description of the problem and solution.

Problem:
Limit View results by the parent post (Grandparent) which is also the page's parent post.

Solution:
Solution here with screenshots: https://toolset.com/forums/topic/limit-view-results-by-the-parent-post-which-is-also-the-pages-parent-post/#post-558160

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

Our next available supporter will start replying to tickets in about 1.11 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 5 replies, has 2 voices.

Last updated by romanB-3 7 years, 3 months ago.

Assisted by: Noman.

Author
Posts
#557656

Hello,
I have this function

add_filter( 'wpv_filter_query', 'filtrer_offres_par_demande', 999, 3 );
function filtrer_offres_par_demande( $query_args, $view_settings, $view_id ) {
    if ( $view_id == 684 ) {
        $query_args['meta_query'][] = array(
                'key'     => '_wpcf_belongs_demande_id',
                'value'   => get_the_ID(),
        );
    }
    return $query_args;
}

that allows me to filter offers by the parent request post (which is called "demande" in the code).
The view is on the single page for the request post type, so it shows only offers for the actual request.

But that's not really what I want : a request is made about a product. Then some offers are registered in answer to this request, and for the same product.

So "product" is parent of both "request" and "offer" post types, and "request" is parent of "offer".

Now I need the filter to be applied on parent product of the request, and not on the request itselft.

How could I code this ?

Thank you.

#557821

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Roman,

Thank you for contacting Toolset support. I am not quite clear on what you are trying to achieve here and which type of limit you would like to apply?

Please provide step by step details (1, 2, 3, 4, etc) so I can understand and suggest you some approach to do that. A simple example would also be nice.

We would like to re-emphasize that the function you have provided is custom one, and we cannot consult on the custom code as it is out of our support policy. https://toolset.com/toolset-support-policy/

When you need custom coding which extends Toolset functionality, we recommend contacting one of Toolset certified service providers: https://toolset.com/consultant/

At times we do provide small code snippets but mostly in cases that can be done quickly in a matter of few minutes. Modifying relational data through code requires more time and more code which we won’t be able to provide. Thanks

#557826

I have 3 custom post types :
PRODUITS
DEMANDES (child of PRODUITS)
OFFRES (child of both PRODUITS and DEMANDES)

The code given allows to filter a view by his parent :
among all OFFRES only show children of current DEMANDE.

What I would need is to change this to :
among all OFFRES only show children of same PRODUIT that is also parent of current DEMANDE

But since OFFRES is also child of DEMANDES, it may be simplier like this :
amond all OFFRES only show grandchildren of parent product of actual DEMANDES

#558124

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for providing more details and explanation. I am still working on it and trying to see what we can achieve in this case. I will soon update you with my findings.

Thank you

#558160

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Step 1.png
Step 2.png
Step 3.png
Step 4.png

I have achieved the desired results using Views filters, so we don’t need code at this point, please backup & remove the code you have added for now. Please follow below steps:

1. I have created a View for Offers and add query filter (Post relationship filter) -- see attached screenshot: Step 1.

2. Create Content Template (e.g. Template for RDemanes) >> assign it to Demands CPT >> and insert Offers View with current Demenad Parent (Product) ID in attribute -- see attached screenshot: Step 2.

3. Now check Demand Single page - (make sure Content Template is applied, see attached screenshot: Step 3.).

I hope this will resolve the issue. Thanks

#558171

Amazing.
Views and Content Templates really are amazing when you know how to use it !
Thank you very much ; this is the best solution I could've think of !