Skip Navigation

[Closed] View – not showing results and add custom meta_query

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 1.26 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by Waqar 1 year, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2540615

hello,

I use the below code to not display items until a filter is clicked:

function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){

$page_id = get_the_ID();

if($page_id == 627 || $page_id == 690 || $page_id == 567 || $page_id == 656) {

// if there is a search term set
if ( !isset( $query_results->query['meta_query'] ) && !isset( $query_results->query['tax_query'] ) && !isset( $query_results->query['s'] ) ) {
$query_results->posts = array();
$query_results->post_count = 0;
$query_results->found_posts = 0;
}
}

return $query_results;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_no_initial_results', 99, 3 );

instead this code to add a custom meta_query, I needed to add a custom one because the below mentioned costum field is only used by one of the post type declared in the query

add_filter( 'wpv_filter_query', 'hide_costum_field_post', 10, 3 );
function hide_expired_events( $query_args, $view_settings, $views_id ) {
$page_id = get_the_ID();

if ($page_id == 690) {
if (!isset($_GET['wpv_filter_submit']) ) { // if it is specific view and by default

$query_args['meta_query'][] = array(
'relation' => 'OR',
array(
'key' => 'wpcf-evento_privato',
'value' => 0,
'compare' => '=',
'type' => 'NUMERIC'
),
array(
'key' => 'wpcf-evento_privato',
'compare' => 'NOT EXISTS'
)
);
}

}
return $query_args;

}

My problem is that adding the last code below, the first code is like it doesn't get executed (obviously because there is !isset( $query_results->query['meta_query'] )), however I would like to be able to add the meta query additional and do not display the items until the filters are clicked

#2541031

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

In your first code snippet, you can replace the condition that checks for the setting of individual types of search filters, i.e.


if ( !isset( $query_results->query['meta_query'] ) && !isset( $query_results->query['tax_query'] ) && !isset( $query_results->query['s'] ) ) {

With a more general condition that checks for whether the search form has been submitted or not:


if (!isset($_GET['wpv_filter_submit']) ) {

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

#2541097

Hi,

Thank you for reply,

Substituting

if ( !isset( $query_results->query['meta_query'] ) && !isset( $query_results->query['tax_query'] ) && !isset( $query_results->query['s'] ) ) 

with

if (!isset($_GET['wpv_filter_submit']) ) 

If I click any filter nothing comes up, no results

#2541835

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back and that is strange.

Can you please share temporary admin login details, so that I can see how these pages and the views are set up in the admin area?

I'll be able to suggest the next steps, accordingly.

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

The topic ‘[Closed] View – not showing results and add custom meta_query’ is closed to new replies.