Skip Navigation

[Resolved] Query Filter by grandparent

This support ticket is created 5 years, 1 month 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)

This topic contains 5 replies, has 3 voices.

Last updated by malagaS 5 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1212230

Tell us what you are trying to do? limit query to grandparent or add an if statement to loop

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site? communicationsteam.com

#1212743

Hi, you can create a View of grandparent posts and apply a Query Filter to limit the results as needed. Then nest a View of parent posts inside that View, and nest a View of child posts inside the parent post View. This approach works best when there are no front-end filters and pagination and loop indexes are not required.

You can create a custom shortcode using the post relationships API, allowing you to test for a specific grandparent post ID using conditionals. I can show you some examples if needed. This approach works best when pagination and loop indexes are not required, but works fine with front-end filters.

If pagination or loop indexes are required, then you must create a custom shortcode that produces a comma-separated list of child post IDs for a given grandparent post ID. Then add a post ID filter to a view of the child posts, set by a shortcode attribute. You can apply any other front-end or backend filters as well. Use your child post IDs View to set the value of the post IDs shortcode.

#1212809

thank you! yes, can you please provide an example? i would need to be able to sort the table by column headings, and i don't think pagination is needed but i may need a text search on the front end.

#1213444

Shane
Supporter

Languages: English (English )

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

Screenshot 2019-03-12 at 3.35.42 PM.png

Hello,

Christian is currently unavailable as he is ill, however he should be back to continue with you here.

It is possible to create a sortable table with views when using the Loop wizard and selecting the table and then selecting the "Make Table header sortable option". See Screenshot.

Thanks,
Shane

#1213724

Hi sorry I was unavailable yesterday. Following up on what Shane said, you can create sortable table columns in Views. However, as we are discussing in another ticket, there is a limitation when displaying information from related posts. It is not currently possible to sort effectively on any criteria from related posts, or to sort by any shortcode that requires an attribute.

Here's an example of a shortcode that will return a grandparent post ID, given a post ID and the two chained post relationship slugs:

function get_grandparent_id_func( $atts )
{
  $a = shortcode_atts( array(
      'postid' => 0,
      'parentrel' => '',
      'grandparentrel' => ''
  ), $atts );

  $parent = toolset_get_related_post( $a['postid'], $a['parentrel']);
  $grandparent = toolset_get_related_post( $parent, $a['grandparentrel']);

  return $grandparent;
}
add_shortcode( 'get-grandparent-id', 'get_grandparent_id_func' );

You would use it like this in a relationship chain like Volume > Book > Chapter, where Volume is the grandparent:

[get-grandparent-id postid="[wpv-post-id]" parentrel="book-chapter" grandparentrel="volume-book"]
#1214338

I'm not sure if I solved the problem or ended up changing course - but what's working for me is a query filter based on a relationship, with the 'specific' grandparent chosen. thank you!

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