hey - thx a lot for all. -
i have one Question about the RFG
in my view (veranstaltungs-liste-date) i would filter about the parent taxonomies.
But this is not working:
<div class="form-group">
<label for="wpv-veranstaltungsart"></label>
[wpv-control-post-taxonomy taxonomy="veranstaltungsart" type="select" url_param="wpv-veranstaltungsart"]
</div>
best regards - alex
Hello, the problem here is similar to the problem in your other ticket. A View can be filtered or sorted by the fields and terms applied to the post type being queried, but not by the fields and terms of its related posts. So in a View of RFGs, it is not possible to filter or sort by the taxonomy terms applied to the related parent post. It is only possible to filter or sort by fields in the RFG.
You could create a View of the parent post type and filter by the parent post taxonomy field, but then the results could not be sorted by the date field in the RFG so the results would appear out of order.
I can help you implement a solution that involves a bit of custom code, but this solution requires you to add a "Submit" button to the filter and disable AJAX updates. Let me know if that is okay, and if you would like to explore that option.
Hi Christian,
oh. - can you show me the filter with the Submit button - That would be great!
thx. - alex
Okay sorry for the delay. The custom code solution involves two Views, both created in the legacy View editor:
1. A View of the parent post type that includes the taxonomy filter and a Search or submit button. You must disable AJAX search options and trigger a page reload when the User clicks the Search or submit button. When you create this View, insert the post title in the loop for testing purposes. This will let you know if the View's taxonomy filter is working correctly.
2. A View of the RFG post type with a post relationship/repeatable field groups owner showing related items of "The post with ID set by the shortcode attribute wpvrelatedto". Order by the date field in this View, and design the loop however you would like to see the results appear.
Place View #1 in the page or template where you want to show the RFG results, and test it to confirm the taxonomy filter is configured correctly. You should see the filtered posts appear when the User clicks the search or submit button. Once you confirm this View is working correctly, edit the View again and click the Loop Wizard button. In the popup, choose the option "List with separators" and insert the post ID field in the loop (see the screenshots loop-wizard-1.png and loop-wizard-2.png). Click Finish to exit the wizard.
Now you should see a comma-separated list of post IDs like 1,2,3,4 instead of the post titles when you reload View #1 on the front-end of the site. Now instead displaying View #1 directly in the page or template, we will display View #2 and pass the results of View #1 into the shortcode attribute wpvrelatedto, like this:
[wpv-view name="view-2-slug" wpvrelatedto="[wpv-view name='view-1-slug']"]
Replace view-2-slug with the slug of View #2, and replace view-1-slug with the slug of View #1.
Now you should see the RFG results appear, sorted by date field, and filtered by the parent post taxonomy. Let me know if you have questions about this approach.
Hi thx for this cool tutorial. I read it very good, all is working but on my Shortcode, the Filter is not working. I think i have all done what you write.
This is the shortcode and site:
enlace oculto
[wpv-view name="veranstaltungs-liste-date-filter01" wpvrelatedto="[wpv-view name='veranstaltungs-liste-filter01']"]
if you need the login, your user is working already 😉
thx a lot - alex
Okay it seems I have left out a step, let me make some changes on your site and give you an update shortly. Thanks for your patience.
Okay please check the filter now:
http://backtofuture.stadttheater-landsberg.de/test-2/
I forgot to add the filters to the page separately with this shortcode:
[wpv-form-view name="veranstaltungs-liste-filter01" target_id="self"]
I have added this shortcode to display only the filters from the custom search View of the parent post type.
After I added the filters, I thought the problem would be solved but the results were not what I expected. It turns out there is a problem with the post relationship filter, and only the results from one parent post would be displayed. I have disabled that post relationship filter for now, and added some custom code to solve that problem. You can find this custom code in a new code snippet in Toolset > Settings > Custom Code for now, but feel free to move it into your child theme if you think that is more appropriate.
// bypass 1 parent problem with post relationship query filter shortcode args
// https://toolset.com/forums/topic/filter-view-of-rfg-by-taxonomy-applied-to-parent-post/
add_filter('wpv_filter_query', 'tssupp_multi_parent_rfg', 101, 3);
function tssupp_multi_parent_rfg($query, $view_settings, $view_id) {
global $WP_Views;
$views = array( 10947 ); // rfg view
$relationship_slug = 'termine-veranst';
$parent_type_slug = 'veranstaltung';
// You should not edit below this line
if ( in_array( $view_id, $views ) ) {
// get the wpvrelatedto shortcode attribute to use as parent query filter
$shortcode_atts = $WP_Views->view_shortcode_attributes[0];
$wpvrelatedto = isset($shortcode_atts['wpvrelatedto']) ? $shortcode_atts['wpvrelatedto'] : 0;
$ids = array();
$parents_args = array(
'post_type' => $parent_type_slug,
'include' => $wpvrelatedto,
'numberposts' => -1
);
$parents = $wpvrelatedto ? get_posts( $parents_args ) : array();
// loop over parents and get children (rfgs), push into post__in for child query
foreach($parents as $parent) {
$children = toolset_get_related_posts(
$parent->ID,
$relationship_slug,
'parent',
1000000,
0,
array(),
'post_id',
'child'
);
if( is_array($children) ) {
foreach( $children as $child ) {
array_push( $ids, $child );
}
}
}
$query['post__in'] = $wpvrelatedto ? $ids : array(0);
}
return $query;
}
Please confirm the results of the filter are as expected, or let me know if there is a problem.
My issue is resolved now. Thank you!