Support

Account

Home Forums Add-ons Repeater Field Repeater field with IF/ELSE based on sub_field value Reply To: Repeater field with IF/ELSE based on sub_field value

  • Yes, I have some pre_get_post filters in place for the CPT pages.

    function my_pre_get_posts( $query ) {
    	global $wpdb;
    
    	// We do not want unintended consequences.
    	if ( is_admin() || !$query->is_main_query() ) {
    		return $query;
    	}
    
    	// Adding all CPTUI post types to the archives
    	if ( is_category() && empty( $query->query_vars['suppress_filters']) ) {
    		// Replace these slugs with the post types you want to include.
    		$cptui_post_types = array( 'inventory', 'auction', 'liquidation' );
    		$query->set(
    	  		'post_type',
    			array_merge(
    				array( 'post' ),
    				$cptui_post_types
    			)
    		);
    	}
    
    	// Include CPTUI post types in Search Results
    	if ( $query->is_search ) {
    
          $query->set( 'post_type', array( 'page','post', 'inventory', 'auction', 'liquidation' ) );
    
      }	elseif(	isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'auction' ) {
    
    			$query->set('numberposts', 12);
    
    	} elseif( $query->query_vars['category_name'] == 'packaging-equipment' || $query->query_vars['category_name'] == 'processing-equipment' || isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'inventory') {
    
    			// remove the archived items from view
    			$query->set( 'cat', '-307' );
    
    			// set the orderby so NEWEST and AVAILABLE are first.
          $query->set( 'meta_query', array(
                array( 'key' => 'statecode' )
            ));
        // another way
        // $query->set('meta_key', 'statecode');
    
    			$query->set( 'orderby', array('meta_value' => 'ASC','date' => 'DESC') );
    
    		// IF item_oem querystring is present, filter posts by value
    		if( isset($_GET['item_oem'] ) && !empty($_GET['item_oem'] )) {
    
    		  // Making the item safe for use.  So there is now HTML embedded.
    		  $oem = htmlspecialchars($_GET['item_oem'], ENT_QUOTES);
    
    			$query->set('post_type', 'inventory');
    			$query->set('meta_key', 'item_oem');
    			$query->set('meta_value', $oem);
    			$query->set('meta_compare', '=' );
    			$query->set( 'orderby', 'meta_value' );
    			$query->set( 'order', 'ASC' );
    
    		// IF show_per_page query string is set, update numberposts to param value to allow visitor to show specific number of posts per page
    	} elseif( isset( $_GET['show_per_page'] ) && !empty($_GET['show_per_page']) ) {
    
    		$show_per_page = htmlspecialchars($_GET['show_per_page'], ENT_QUOTES);
    		$query->set('posts_per_page', $show_per_page);
    
    	} elseif( isset( $_GET['newly_acquired'] ) && $_GET['newly_acquired'] == 'true' && is_post_type_archive('inventory')) {
    
    			$query->set('post_type', 'inventory');
    
    			// let's only show items from the last 30 days.. when the button is clicked.
    			$date_query = array(
     				array(
     					'after' => '-30 days',
     					'column'=> 'post_date',
     					),
    				);
    
    			// set the date for the query
    			$query->set( 'date_query', $date_query 	);
    
    		} else {
    
    			$query->set( 'posts_per_page', 12 );
    
    		}
    	}
    
    	// set loop for articles, employment and case study archives
    }
    add_filter( 'pre_get_posts', 'my_pre_get_posts', 99999);