Support

Account

Home Forums General Issues Create filter by year on archive page Reply To: Create filter by year on archive page

  • @hube2 Thank you!

    It’s done.

    I used this ‘pre_get_posts’ function –

    add_action( 'pre_get_posts', 'my_pre_get_posts' );
    
    function my_pre_get_posts( $query ) {
    	if ( is_admin() ) {
    		return $query;
    	}
    
    	if ( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'post' ) {
    		if( isset($_GET['press']) ) {
    			$query->set('meta_key', 'press');
    			$query->set('meta_value', $_GET['press']);
    		}
    	}
    
    	return $query;
    }