Skip Navigation

[Resolved] View and Filter for Taxonomy of Children Posts

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

Problem: I would like to create a View of post type "A" but filter by a field in related post type "B".

Solution: Right now, it's not possible to filter by fields in related posts. The only solution is to duplicate data across posts.

add_action( 'save_post', 'auto_set', 100, 3 );
function auto_set( $post_id, $post, $update ) {
  if( $post->post_status == 'publish' && $post->post_type =='child-post-type-slug' ) {
    $parent_id = toolset_get_related_post( $post_id, 'post-relationship-slug' , 'parent', array() );
    $field_value = get_post_meta( $parent_id, 'wpcf-custom-field-slug', true );
    update_post_meta( $post_id, 'wpcf-custom-field-slug', $field_value );
  } 
}
This support ticket is created 5 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.

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
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 2 replies, has 2 voices.

Last updated by garyF-3 5 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1230406

Tell us what you are trying to do?
I have a one to many relationship - One Product can have many Experiences.

Assigned to the Experiences is a taxonomy cal XP Experiences

What I want to do is create a filter on the parent posts as follows:

1. Filter on parent posts (show all then filter) based on custom fields assigned to parent posts
2. Filter on parent posts (show all then filter) based on the CHILD posts taxonomy that are linked to the Parent Post

Filters 1 and 2 to be on the same view - so offer different filter options

#1230668

Hi, in order to do this with front-end filters you would need to be able to filter upon fields or taxonomies of related post types. That's not currently possible. So right now you could either filter a View of parent posts by fields on the parent post, or you could filter a View of child posts by taxonomy terms on the child posts and display the parent post in the results using Views shortcodes, but there's no simple combination of both.

Another practical option I can think of is to duplicate data across both posts somehow, either by assigning the child post taxonomy automatically to the parent post or by assigning the parent field information to the child posts automatically. If you assign the parent field information to the child posts automatically, you could create a View of the child posts and display the parent Product information in the loop of the View. Here's an example of setting a custom field value on a child post automatically, based on the parent post, whenever the child post is saved:

add_action( 'save_post', 'auto_set', 100, 3 );
function auto_set( $post_id, $post, $update ) {
  if( $post->post_status == 'publish' && $post->post_type =='child-post-type-slug' ) {
    $parent_id = toolset_get_related_post( $post_id, 'post-relationship-slug' , 'parent', array() );
    $field_value = get_post_meta( $parent_id, 'wpcf-custom-field-slug', true );
    update_post_meta( $post_id, 'wpcf-custom-field-slug', $field_value );
  } 
}

Then in the loop:

Parent post: [wpv-post-title item="@post-relationship-slug.parent"]
#1230675

My issue is resolved now. Thank you!