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 - 316 through 330 (of 428 total)
Problem:
How to have a default search filter value if none is selected by the user, e.g. on the initial page load?
Solution:
You can use the Views API filter wpv_filter_query to modify the underlying query so that if no filter value has been specified then the default is set. The code becomes slightly more complex if you need to allow for the possibility that there are other filters available in the same search that may or may not have been set aside from the filter to which you wish to apply a default.
Problem:
How to include posts with a status of "Pending review" in the output of a View.
Solution:
By default a View will only list published or private posts. To include other statuses it is necessary to use the wpv_filter_query API filter to modify the query arguments.
An example of such code would be:
function ts_filter_query( $view_args, $view_settings, $view_id ) {
if ( in_array( $view_id, array( 117 ) ) ) { // list of View IDs to apply this to
$view_args['post_status'] = array( 'publish', 'pending' );
}
return $view_args;
}
add_filter( 'wpv_filter_query', 'ts_filter_query', 101, 3 );
Problem: I have a View of Users I would like to sort by role.
Solution: The standard WordPress User Query isn't sortable by role so this is unfortunately a limitation of the WordPress system. We do offer some PHP APIs that you can use to add your own custom sorting.