John
Support threads created in the last 30 days: 0
Favorite Forum Topics
This user has no favorite topics.
Forum Topics Created
Status | Topic | Supporter | Voices | Posts | Freshness |
---|---|---|---|---|---|
getting added to each wpv-post-body
Started by: John in: Toolset Professional Support |
1 | 2 | 2 years, 6 months ago | ||
Many to many relationship w multiple child records
Started by: John
in: Toolset Professional Support
Problem: Link two posts within a Many-to-many relationship multiple times Solution: You can connect the same two posts only once with the same post type relationship. As a workaround, you can setup two one-to-many relationships to replace the many-to-many, for example: https://toolset.com/forums/topic/many-to-many-relationship-w-multiple-child-records/#post-2366553 Relevant Documentation: |
2 | 3 | 2 years, 6 months ago | ||
View filter by multiple parents
Started by: John
in: Toolset Professional Support
Problem: I have a post type that is a child of two parent post types. I would like to filter a View of my child posts by post relationship, including both parent post types filters. I would like to pass the parent IDs into the View filters as URL parameters. Solution: Add hidden input fields that access the URL parameters using the custom wpv-post-params shortcode. Then modify the query using wpv_filter_query to create a combined meta query using both parent types. // access any url parameter // [wpv-post-param var="someparam"] add_shortcode( 'wpv-post-param', 'wpv_post_param_shortcode' ); function wpv_post_param_shortcode( $atts ) { if ( !empty( $atts['var'] ) ) { $var = (array)$_GET[$atts['var']]; return esc_html( implode( ', ', $var ) ); } } // combine parent post type relationship filters add_filter( 'wpv_filter_query', 'filter_both_parent_types', 10, 3 ); function filter_both_parent_types ( $query, $view_settings, $view_id ) { if( $view_id == 1234 ) { $selected_parent1 = isset($_GET['bookid']) ? $_GET['bookid'] : null; $selected_parent2 = isset($_GET['authorid']) ? $_GET['authorid'] : null; $args = array( 'relation' => 'AND', array( 'key' => '_wpcf_belongs_book_id', 'value' => $selected_parent1, 'compare' => '=', 'type' => 'numeric' ), array( 'key' => '_wpcf_belongs_author_id', 'value' => $selected_parent2, 'compare' => '=', 'type' => 'numeric' ) ); // add these arguments to your meta query $query['meta_query'] = isset($query['meta_query']) ? $query['meta_query'] : []; $query['meta_query'][] = $args; } return $query; } Relevant Documentation: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query |
2 | 6 | 7 years, 2 months ago |