-
Search Results
-
Topic: Query issues
Hey, guys!
We’re trying to display posts differently for logged in users and anonymous users (i.e. some posts are available only for logged in users). The problem is that when connecting to the ‘sf_edit_query_args_after_custom_filter’ hook the cache query is affected and the results are incomplete; the ‘sf_edit_query_args’ hook the cache works correctly but the listing displays wrong counter.
My question is: is there any hook that can alter only the results displayed so that the cache query is not affected?
Bellow is the code needed to run on the results found:function _query_filter($query_args, $sfid) { $post_type = get_query_var( 'post_type' ); $affected_post_types = array( 'module', 'learning-object', 'success-story' ); if ( !is_post_type_archive( $affected_post_types ) || is_admin() ) { return $query_args; } // echo '<pre>'; print_r( get_query_var( 'post_type' ) ); echo '</pre>'; exit; $meta_query = array( 'relation' => 'AND' ); $posts_per_page = '12'; $post_status = array( 'publish' ); if ( is_user_logged_in() ) { if ( current_user_can('partner') || current_user_can('manage_options') || ( current_user_can( 'member' ) && preg_match( '/^(\/step\/)/i', $_SERVER['REQUEST_URI'] ) ) ) { $post_status[] = 'draft'; $post_status[] = 'private'; $post_status[] = 'internal'; } } $query_args['orderby'] = 'date'; $query_args['order'] = 'DESC'; if ( $post_type != 'learning-object' ) { $posts_per_page = 6; } if ( !isset( $_GET['_sfm_language'] ) ) { $selected_language = ''; if ( !defined( 'ICL_LANGUAGE_CODE' ) ) { define( 'ICL_LANGUAGE_CODE', 'en' ); } switch ( ICL_LANGUAGE_CODE ) { case 'fi': $selected_language = 'Finnish'; break; case 'de': $selected_language = 'German'; break; default: $selected_language = 'English'; break; } // $meta_query[] = array( // 'relation' => 'OR', // array( // 'key' => 'language', // 'compare' => 'NOT EXISTS' // ), // array( // 'key' => 'language', // 'value' => $selected_language // ) // ); } if ( !is_user_logged_in() ) { $meta_query[] = array( 'relation' => 'OR', array( 'key' => 'is_public', 'compare' => 'NOT EXISTS' ), array( 'key' => 'is_public', 'value' => 'yes' ) ); } $query_args['post_status'] = $post_status; $query_args['meta_query'] = $meta_query; $query_args['posts_per_page'] = $posts_per_page; // echo '<pre>'; print_r( $query_args ); echo '</pre>'; return $query_args; } // add_filter( 'sf_edit_query_args', '_query_filter', 10, 2 ); add_filter( 'sf_edit_query_args_after_custom_filter', '_query_filter', 10, 2 );
Also, how can we update the counters to reflect only the displayed results?
Topic: Can not alter order
Hi Trevor,
some of my WooCommerce products have a meta key “_tribe_event_starttime” and with your plugin I have setup an AJAX filter ordering these products by that meta key.
Everything was fine for weeks but today I realized that the order has fallen back to the WC default (creation) “date”. You can see the result list by clicking on one of the big images on the top.https://obsthof-am-steinberg.de/produkt-kategorie/event-feste-kinder-musik/
As you can see the AJAX requests has the GET parameter orderby=date and I tried to alter this order by hooking into your filter which I found here on your website:
// alter query for search & filter results
add_filter( ‘sf_edit_query_args’, ‘sf_orderby_eventdate’, 10, 2 );
function sf_orderby_eventdate ($query_args, $sfid) {
if ($sfid == 6047) {
$query_args[“meta_key”] = ‘_tribe_event_starttime’;
$query_args[“order_by”] = ‘meta_value’;
$query_args[“order”] = ‘ASC’;
}
return $query_args;
}Without success. I have installed WP Super Cache last week. Could this be the reason? Is there anything I missed or doing wrong?
Thank you for your support!
OliverNow I am