-
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?