I am trying to:
I've created a view that displays a cpt called 'dances', there are two filters applied, one for the 'entertainer' who performed the dance (that filter works fine), the other is a date time filter that uses a custom shortcode ([dailydances]) to capture the epoch time of the previous day at 1pm, and compare it to the date captured in a date-time field for the 'dance' cpt. Any dances that took place after the previous day at 1pm should populate the view, but the comparison does not appear to be working correctly as I always get all entries returned.
add_shortcode( 'dailydances', 'yls_daily_dances' );
function yls_daily_dances() {
$today = strtotime('13:00:00');
$yesterday = strtotime('-1 day', $today);
return $yesterday;
}
Link to a page where the issue can be seen:
It's in my local dev environment, but the screenshots should provide what you need. Note in the filter-example I've applied the filter, and as you'll see I printed the shortcode for easy comparison. The last two entries should not be visible as they took place before 'yesterday at 1pm'.
Hi, have you registered the custom shortcode in Toolset > Settings > Frontend Content > Third Party Shortcode Arguments? That's the first thing you should confirm. Then if that's not the problem, please copy + paste the exact shortcode combination you are using to insert the View. I'll take a quick look and see if anything looks out of place.
Yes I've registered the shortcode, please see the attached screen. I'm only using the shortcode in the filter for the view as the previous screenshot 'view-filters' shows. The below is what is used to insert the view on the page.
<div class="wp-block-toolset-view">[wpv-view name="daily-dance-report"]</div>
Okay I see the confusion here. When you type "dailydances" as the Shortcode value in the Query Filter, this is the name of the shortcode attribute that will be used to supply the dynamic filter value. It has nothing to do with the custom shortcode you created per se, except that you will combine the two in the View shortcode to pass the dynamic value into the filter. You must update your View shortcode as shown here:
<div class="wp-block-toolset-view">[wpv-view name="daily-dance-report" dailydances="[dailydances]"]</div>
There is a shortcode attribute "dailydances" because that's what you chose to call it in the Query Filter. The nested dailydances shortcode is the custom shortcode you created to supply the filter a dynamic value. Both are required to make the Query Filter respond to your custom shortcode. It is not necessary to name them identically. Make sense?
My issue is resolved now. Thank you!