Views plugin provides an API, making it easy to display Views output using PHP.
When you ask for help or report issues, make sure to tell us all related information about your View and the data that you want to display using the Views API.
Viewing 15 topics - 331 through 345 (of 454 total)
Problem:
Filter taxonomy with taxonomy with first character - glossary, abc filter
Solution:
You can use the taxonomy view's filter hook "wpv_filter_taxonomy_query" with "terms_clauses" hook in order to filter the taxonomy term names with selected first character.
Problem:
How can I make a Custom Date Filters greater than today?
Solution:
Custom field created using Types plugin and you want to filter your event posts for future events. i.e. "Only the events dates higher than today" (YYYYMMDD > YYYYMMDD).
Problem: I have a View with two custom field filters. The first filter is applied using a shortcode attribute. The second filter is a front-end filter using a datepicker field. I can set the default date using TODAY(), but the initial result is not filtered. I would like to filter the initial results, and allow the User to change the filter as needed.
Solution:
It's possible to filter the initial result set using the default selection TODAY while still allowing front-end date filtering. Add the following code to your child theme's functions.php file, or to a new snippet in Toolset > Settings > Custom Code:
add_filter( 'wpv_filter_query', 'filter_gte_today', 10, 3 );
function filter_gte_today ( $query, $view_settings, $view_id ) {
$views = array( 12345 );
$date_slug = 'wpcf-stdstartdate';
$url_param = 'wpv-wpcf-stdstartdate';
// do not edit below this line
if( in_array( $view_id, $views) ) {
// check to see if the datepicker filter has been manually set or manually unset
// if so, bail out and don't modify it
if( isset($query['meta_query'])) {
$cols = array_column($query['meta_query'], 'key');
if( in_array($date_slug, $cols) || ( isset( $_GET[$url_param] ) && $_GET[$url_param] == '' )) {
return $query;
}
}
// datepicker filter has not been set or unset. Use the default value.
$today = strtotime('0:00');
$args = array(
'relation' => 'AND',
array(
'key' => $date_slug,
'value' => $today,
'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;
}
Change 12345 to match the numeric ID of this View. Change wpcf-stdstartdate to match the date field slug. You must use the 'wpcf-' prefix here. Change wpv-wpcf-stdstartdate to match the URL parameter specified in your Query filter.
Problem: I would like to use a conditional to test the output of a Content Template using a post ID from a custom field in the current post. It may be empty or it may have some content. I would like to be able to test that value with conditional HTML, but it's not working as expected.
Solution: If you exceed the maximum nesting depth level, the conditional engine will have problems deciphering the sequence of nested quotation marks. Usually the best practice here is to create a custom shortcode that does not require so many nested attributes and shortcodes.