Tell us what you are trying to do?
I have a nested view. Both views are not connected through a relationship. When I update the URL_PARAM of the inner VIEW, then the URL_PARAM of the outer VIEW is removed and the outer VIEW jumps back to its original state. Can I prevent that somehow. It would be extremly useful, if I could keep the URL_PARAM of the outer view, even if I change the URL_PARAM of the inner VIEW.
The funny thing is, it works the other way round. If I change the URL_PARAM of the outer VIEW, the URL_PARAM of the inner VIEW maintains.
My "Custom Search Settings" are "Full page refresh when visitors click on the search button".
Is there any documentation that you are following?
no
Is there a similar example that we can see?
no
What is the link to your site?
hidden link But the issue can not be seen, without being registered.
Hello, I think I would need to log in and see how the Views and filters are set up, then follow some step-by-step instructions to understand the problem better. Can you provide login credentials in the private reply fields here? Then tell me step-by-step how to produce the problem, and what you would like to see instead in the URL and results.
I'll take a look and see what is possible in this nested setup. Thank you!
Okay I see, thanks for the additional information. I can see that you have custom search filters visible from two nested Views, but this is a problem because only one set of custom search filters is supported in a custom search View system. A nested View should not provide custom search filters like this, and will cause problems like you are experiencing now, because the filters from the outer View will not be maintained when the filters from the inner View are manipulated. Unfortunately there is no good solution that allows you to display custom search filters from two separate Views in the same custom search experience - only one custom search filter system from one View should be visible.
In this case, the best solution might be to duplicate some custom field data across posts. You could set up some custom code that copies the values of the "RASK | Datum des Tages" fields from the Tage posts and automatically inserts them into the same custom fields in its related Termine and Events posts. Then you would set up all the custom search filters in one View, to filter by the fields in the Termine and Events posts instead of the Tage posts.
Example custom code to copy field from parent into child posts:
https://toolset.com/forums/topic/view-and-filter-for-taxonomy-of-children-posts/
You could use the save_post hook to listen to the event when Tage posts are saved, and then use the post relationships API to find the related Termine and Events posts, and copy the field values automatically that way. You could also use the save_post hook to listen to the event when Termine and Events posts are created or edited, use the post relationships API to find their related Tage posts, and import the custom field values automatically.
If the posts are created and edited using front-end Forms, we also have some Forms APIs you can use to trigger your own custom code.
save_post hook: https://developer.wordpress.org/reference/hooks/save_post/
Forms API cred_submit_complete: https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete
Post relationships API: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
Let me know if you have questions about how to set up this kind of automatic process to copy field values across posts, and I can offer some more direct guidance.
Hello Christian,
the problem is that the outer VIEW functions as a calender. So the loop has to output all days between the start-day and the end-day. No matter, if they contain an entry (inner VIEW) or if there is no entry.
The inner VIEW lists all the enties for a given day. All entries can have different locations.
The entries in the inner view already possess a date field.
They only appear in the "Loop Output" of the inner VIEW, if the date of the "entry" is the same as the date of the given calender day.
If I use URL_PARAM for
- location
- start date
- end date
of the inner view, is there a way (through custom code e.g.), that the filter value for start date and end date will also be applied for the outer view simultaneously?
If I use URL_PARAM for
- location
- start date
- end date
of the inner view, is there a way (through custom code e.g.), that the filter value for start date and end date will also be applied for the outer view simultaneously?
There's nothing special you need to do. If the URL parameters exist when the page loads, the outer View will automatically respond to them as long as you have Query Filters set up in the outer View to respond to URL parameters.
Oh that's cool, thanks Christian.
I have a last question.
At the moment I use the date field to "connect" the outer and the inner view. Through a "Shortcode Attribute PARAM" I get the date of the current post in the outer view and apply it as a "Shortcode Attribute PARAM FILTER" to the inner VIEW.
However I can not use both. A "Shortcode Attribute PARAM FILTER" and a "URL_PARAM FILTER" for the same field.
Is there a way who I can grab the "Shortcode Attribute PARAM" from the outer view in PHP? I'm ok with writing a custom query in PHP as a workaround, but I don't know how to grab the value
I'm not quite sure I understand why you would need to access the shortcode param in PHP. If you want the inner View to respond to a shortcode parameter, you can configure the inner View's Query Filter to respond to a shortcode parameter, then pass it into the inner View directly in the Views shortcode from the outer View using the wpv-attribute shortcode. For example:
[wpv-view name="outer-view" param1="something"]
Then inside the outer-view loop, place the inner View using a shortcode like so:
[wpv-view name="inner-view" param2="[wpv-attribute name='param1']"]
Now in the inner View, param2 has the value of param1 from the outer View.
Or if you need something specific in PHP, please provide a bit more detail.
I'm sorry I explained it poorly.
Please view the attached image.
Okay, thanks, I think I misunderstood how the outer and inner View are set up. I think in this case the inner view's Query Filter should be configured to respond to the shortcode attribute, since the date field will be passed in by the outer view. If I understand correctly, the outer View will respond to the URL parameter date range instead of the inner View.
I changed it. Now the inner view's Query Filter is configured to respond to the shortcode attribute. However as long as I have this code..
<div id="day_filter" style="width: 100%; margin-bottom: 5px !important; display: flex; flex-direction: row; flex-wrap: nowrap; justify-content: space-between;">
<div style="display: flex; flex-direction: row; flex-wrap: nowrap; justify-content: flex-start; background-color: #fff !important; color: #363a61; width: 49.5%;">
<span style="padding: 6px 4px 6px 8px; width: 50px;">VON</span>
[wpv-control-postmeta type="date" field="wpcf-rask-von-tag" default_date="TODAY()" url_param="wpv-wpcf-rask-von-tag_min"]</div>
<div style="display: flex; flex-direction: row; flex-wrap: nowrap; justify-content: flex-start; background-color: #fff !important; color: #363a61; width: 49.5%;">
<span style="padding: 6px 4px 6px 4px; width: 50px;">BIS</span>
[wpv-control-postmeta type="date" field="wpcf-rask-von-tag" default_date="FUTURE_DAY(6)" url_param="wpv-wpcf-rask-von-tag_max"]</div></div>
... which represents the URL_PARAM of the date field in question within the inner view in the section "Search and Pagination", then the "shortcode attribute query filter" doesn't kick in.
Okay let me see if I can override the URL param with some custom code. I'll work on a filter and give you an update shortly.
Okay I set up a similar nested structure locally and was able to bypass the URL parameter on the inner View with a shortcode attribute using our wpv_filter_query API filter. Please add this custom code to your child theme's functions.php file, or create a new custom code snippet in Toolset > Settings > Custom Code and append this code to the end of the snippet:
// toolset support -
// override inner View url param with shortcode attribute passed from outer view
// https://toolset.com/forums/topic/nested-view-filter-child-and-parent-posts-through-url_param/
add_filter('wpv_filter_query', 'tssupp_force_shortcode_over_param', 99, 3);
function tssupp_force_shortcode_over_param($query, $view_settings, $view_id) {
global $WP_Views;
$views = array( 12345 );
$inner_view_slug = "inner-view-slug";
$param_name = "startdateparam";
$field_slug = "inner-date-field-slug";
// You should not edit below this line
if ( in_array( $view_id, $views ) ) {
// get the shortcode attribute value to use in date field meta filter
$shortcode_atts = $WP_Views->view_shortcode_attributes;
$param_value = '';
// find correct index of nested shortcode attributes for inner view
foreach($shortcode_atts as $att){
if($att['name'] == $inner_view_slug) {
$param_value = isset($att[$param_name]) ? $att[$param_name] : null;
$set = false;
// replace any existing meta_query for this custom date field with
// param date comparison
$query['meta_query'] = isset($query['meta_query']) ? $query['meta_query'] : [];
foreach($query['meta_query'] as $met=>$val) {
if(isset($val['key']) && $val['key'] == 'wpcf-' . $field_slug){
$query['meta_query'][$met]['value'] = $param_value;
$query['meta_query'][$met]['compare'] = '=';
$query['meta_query'][$met]['type'] = 'NUMERIC';
$set = true;
}
}
// if date meta_query is still not set, there were no date filters
// initially applied, so we must set the date filter here
if(!$set) {
$meta_query_args = array(
'key' => 'wpcf-' . $field_slug,
'value' => $param_value,
'compare' => '=',
'type' => 'NUMERIC'
);
array_unshift($query['meta_query'], $meta_query_args);
}
break;
}
}
}
return $query;
}
- Replace 12345 with the numeric ID of the inner View.
- Replace inner-view-slug with the slug of the inner View.
- Replace startdateparam with the name of the start date shortcode argument for the inner View.
- Since only one date is needed for the inner View (not a date range, but a single date from the current post in the outer View), you can delete the end date shortcode argument from the inner View shortcode.
- Replace inner-date-field-slug with the slug of the date field for posts in the inner View.
Please let me know the results after adding this custom filter code.
My issue is resolved now. Thank you!
Many thanks Christian.
The code snippet works like a charm.