使用! is_admin()将限制此过滤器仅在前端使用,以避免后端出现许多问题:
// Only show products in the front-end search results
add_filter('pre_get_posts','lw_search_filter_pages');
function lw_search_filter_pages($query) {
// Frontend search only
if ( ! is_admin() && $query->is_search() ) {
$query->set('post_type', 'product');
$query->set( 'wc_query', 'product_query' );
}
return $query;
}
这是观点的一部分。
<div class="row">
@if($events->count())
@if($eventListView == "grid")
<div class="col-sm-12 grid-search">
<div class="col-sm-offset-6 col-sm-6">
<div class="pull-right lh-2">
Search: <input class="form-control pull-right input-sm grid-filter">
</div>
</div>
</div>
@foreach($events as $key => $event)
<div class="col-md-6 col-sm-6 col-xs-12 data-event-block" data-event-block="{{ $key+1 }}" style="display: {{ $key <= 9 ? 'block' : 'none' }}">
@include('ManageEmsPro.Partials.EventPanel')
</div>
@endforeach
@elseif($eventListView == "table")
<div class="col-md-12">
@include('ManageEmsPro.Partials.EventTable')
</div>
@endif
@else
@if($search['q'])
@include('Shared.Partials.NoSearchResults')
@else
@include('ManageEmsPro.Partials.EventsBlankSlate')
@endif
@endif
</div>
回首忆惘然