Menu disappears when meta_key changed
-
Hi.
I sent you the link in the attachment so you can see that menu disappears on custom filter change below. If you choose ‘most recent’ (that not affects meta_key) menu shows nicely, but if you choose price, all menus disappear.
Here is the code:
if ( ! function_exists( 'noo_landmark_addon_pre_get_posts' ) ) : function noo_landmark_addon_pre_get_posts( $query ) { if ( is_admin() ) { return $query; } if ( $query->is_main_query() && $query->is_singular ) { return; } /** * Set query in archive property */ if ( RP_Property::is_property() ) { $args = array(); /** * Check order */ $default_orderby = isset( $query->query_vars[ 'orderby' ] ) ? $query->query_vars[ 'orderby' ] : get_theme_mod( 'noo_property_listing_orderby', 'date' ); $orderby = isset( $_GET[ 'orderby' ] ) ? sanitize_text_field( $_GET[ 'orderby' ] ) : $default_orderby; $orderby = strtolower( $orderby ); $order = isset( $query->query_vars[ 'order' ] ) ? $query->query_vars[ 'order' ] : 'DESC'; $args[ 'orderby' ] = $orderby; $args[ 'order' ] = $order == 'DESC' ? 'DESC' : 'ASC'; $args[ 'meta_key' ] = ''; // global filter if ( isset($_GET['recent_first']) ) { $args[ 'orderby' ] = 'date'; $args[ 'order' ] = sanitize_text_field($_GET['recent_first']); } if ( isset($_GET['property_price']) ) { $args[ 'orderby' ] = 'meta_value_num meta_value'; $args[ 'order' ] = sanitize_text_field($_GET['property_price']); $args[ 'meta_key' ] = 'price'; } $query->set( 'orderby', $args[ 'orderby' ] ); $query->set( 'order', $args[ 'order' ] ); if ( isset( $args[ 'meta_key' ] ) && ! empty( $args[ 'meta_key' ] ) ) { $query->set( 'meta_key', $args[ 'meta_key' ] ); } if ( isset( $args[ 'meta_value' ] ) && ! empty( $args[ 'meta_value' ] ) ) { $query->set( 'meta_value', $args[ 'meta_value' ] ); } if ( isset( $args[ 'meta_query' ] ) && ! empty( $args[ 'meta_query' ] ) ) { $query->set( 'meta_query', $args[ 'meta_query' ] ); } /** * Set number show posts */ $property_per_page = get_theme_mod( 'noo_property_per_page', 10 ); $query->set( 'posts_per_page', $property_per_page ); $query->set( 'post_status', 'publish' ); } /** * Set query in archive agent */ if ( RP_Agent::is_archive_agent() ) { $agent_per_page = get_theme_mod( 'noo_agent_per_page', 10 ); $query->set( 'posts_per_page', $agent_per_page ); $agent_must_has_property = Realty_Portal::get_setting( 'agent_setting', 'agent_must_has_property', false ); if ( $agent_must_has_property === '1' ) { query_posts( 'post_type=noo_agent&posts_per_page=-1' ); $agent_ids = array(); while ( have_posts() ) : the_post(); $agent_id = get_the_ID(); $user_id = RP_Agent::get_id_user( $agent_id ); if ( $user_id < 1 ) { continue; } $total_property = count_user_posts( $user_id, 'noo_property' ); if ( $total_property > 0 ) { $agent_ids[] = $agent_id; } endwhile; wp_reset_query(); $query->set( 'post__in', $agent_ids ); } } } add_action( 'pre_get_posts', 'noo_landmark_addon_pre_get_posts' ); endif;
The page I need help with: [log in to see the link]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Menu disappears when meta_key changed’ is closed to new replies.