Support » Plugin: Pods - Custom Content Types and Fields » Pod filtering/search questions

  • Resolved maykelesser

    (@maykelesser)


    I have the following filter to my page:

    <aside class="col-sm-3">
    	<?php 
    
    		$pod = pods('convite');
    		echo $pod->filters(
    			array( 
    				'fields' => array('curso','acabamentos','titulo'),
    				'label' => 'Filtrar'
    			)
    		);
    
    	?>
    </aside>
    <div class="col-sm-9">
    	<div class="row post-convite">
    		<?php 
    
    			$pod = pods('convite'); 
    			$params = array('limit' => 20); 
    			$pod->find($params);
    
    			while ($pod->fetch()){
    
    				$image = wp_get_attachment_image_src($pod->field("imagens")[0]['ID'], 'thumb-convite');
    
    				echo "
    				<div class=\"col-lg-6\">
    					<a href=\"\" title=\"".$pod->display('titulo', true)."\">
    						<span class=\"image\">
    							<img src=\"".$image[0]."\" class=\"img-fluid\" width=\"".$image[1]."\">
    						</span>
    						<span class=\"info\">
    							<h3>".$pod->display('titulo', true)."<br><small>Ref: ".$pod->display('referencia', true)."</small></h3>
    							<p>".ucfirst(mb_strtolower($pod->display('acabamentos')))."</p>
    							<div class=\"clearfix\"></div>
    						</span>
    					</a>	
    				</div>";
    			}
    
    			$pod->reset();
    
    		?>
    	</div>
    	<?php echo $pod->pagination(array('type' => 'advanced')); ?>
    </div>

    #1
    It works ok, but i want to insert a heading (h3) above each filter input/select. How can i do this?

    #2
    I’ve tried to build a manual search, however, when I query and the URL is changed, my “filters” are being filtered as well.

    <aside class="col-sm-3">
    	<form method="GET">
    		<h3>Cursos</h3>
    		<?php
    
    			$cursos = pods('curso', ["limit" => -1]);
    		    $arrayCursos = [];
    		    $divCurso = "";
    		    
    		    if ($cursos->total() > 0) {
    		        while ($cursos->fetch()) {
    		            $arrayCursos[] = [
    		                "id"    => $cursos->display("ID"),
    		                "title" => $cursos->display("titulo"),
    		                "slug"  => get_post_field( 'post_name', get_post())
    		            ];
    		        }
    		    }
    
    		    $divCurso .= "<select name=\"filter_curso\">
    		    				<option value=\"\">---</option>";
    
    		    for($i = 0; $i < count($arrayCursos); $i++){
    		    	$divCurso .= ($_GET['filter_curso'] == $arrayCursos[$i]['id']) ? "<option selected value=\"".$arrayCursos[$i]['id']."\"> ".ucfirst(mb_strtolower($arrayCursos[$i]['title']))."</option>" : "<option value=\"".$arrayCursos[$i]['id']."\"> ".ucfirst(mb_strtolower($arrayCursos[$i]['title']))."</option>";
    		    }
    
    		    $divCurso .= "</select>";
    
    		    echo $divCurso;
    
    		?>
    		<hr>
    		<h3>Acabamentos</h3>
    		<?php
    
    			$acabamentosPods = pods('convite', ["limit" => -1]);
    		    $acabamentos = array();
    		    $divAcabamento = "";
    
    		    while ($acabamentosPods->fetch()) {
    		        foreach ($acabamentosPods->field("acabamentos") as $item){
    		            if (!in_array($item, $acabamentos)) { 
    		            	$acabamentos[] = $item;
    		            }
    		        }
    		    }
    
    		    for($i = 0; $i < count($acabamentos); $i++){
    		    	$divAcabamento .= "<li><input name=\"cbAcabamento[]\" value=\"".$acabamentos[$i]."\" type=\"checkbox\"> ".ucfirst(mb_strtolower($acabamentos[$i]))."</li>";
    		    }
    		    
    		    echo $divAcabamento;
    
    		?>
    		<hr>
    		<h3>Código de ref.</h3>
    		<input type="text" name="search" placeholder="Código" <?php if(!empty($_GET['search'])){ echo "value=\"".$_GET['search']."\""; } ?>>
    		<hr>
    		<input type="submit" value="Filtrar">
    	</form>
    </aside>
    <div class="col-sm-9">
    	<div class="row post-convite">
    		<?php 
    
    			$pod = pods('convite'); 
    			$params = array('limit' => 20); 
    			$pod->find($params);
    
    			while ($pod->fetch()){
    
    				$image = wp_get_attachment_image_src($pod->field("imagens")[0]['ID'], 'thumb-convite');
    
    				echo "
    				<div class=\"col-lg-6\">
    					<a href=\"\" title=\"".$pod->display('titulo', true)."\">
    						<span class=\"image\">
    							<img src=\"".$image[0]."\" class=\"img-fluid\" width=\"".$image[1]."\">
    						</span>
    						<span class=\"info\">
    							<h3>".$pod->display('titulo', true)."<br><small>Ref: ".$pod->display('referencia', true)."</small></h3>
    							<p>".ucfirst(mb_strtolower($pod->display('acabamentos')))."</p>
    							<div class=\"clearfix\"></div>
    						</span>
    					</a>	
    				</div>";
    			}
    
    			$pod->reset();
    
    		?>
    	</div>
    	<?php echo $pod->pagination(array('type' => 'advanced')); ?>
    </div>

    Can anyone help me with these issues?

Viewing 1 replies (of 1 total)
  • Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    So technically you can build out your own input/selects yourself, you can follow how we do it in /ui/front/filters.php, and you can customize it all. However! You can totally override our filters.php view there by simply filtering pods_view_alt_view and adding this code:

    
    /**
     * Override the ui/front/filters.php view for Pods.
     *
     * @param null|bool  $filter_check If not set to null, this filter will override the view response.
     * @param string     $view         Path of the view file.
     * @param array|null $data         Data to pass on to the template.
     *
     * @return bool|string
     */
    function my_pods_front_filters_view_override( $filter_check, $view, $data ) {
    	// If this view is already being overridden, bypass our filter override.
    	if ( null !== $filter_check ) {
    		return $filter_check;
    	}
    
    	// Only override the filters.php view.
    	if ( PODS_DIR . 'ui/front/filters.php' === $view ) {
    		/*
    		 * This will use the path/to/your/file.php relative to your theme/child theme but you can provide
    		 * the full server path within a plugin or theme folder too.
    		 */
    		return pods_view( 'path/to/your/file.php', $data );
    	}
    
    	return $filter_check;
    }
    
    add_filter( 'pods_view_alt_view', 'my_pods_front_filters_view_override', 10, 3 );
    

    Be sure to change the path of your file override to where you will put your filters.php override, and also be sure to copy the code we have in our current filters.php so you can customize it how you see fit. This way, you don’t have to change your $pod->filters() usage at all.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.