• dpope0824

    (@dpope0824)


    I have a filter that loads all posts and then filters from there. Is there any way to have posts hidden but able to be seen with a Show More button and still filterable without being displayed. I know this may not be possible but if it is would save me a lot of time and headache. This would also be useful for other sites that have alot of content and need filtering without clogging up the page.

    <?php
    
    	if(isset($_POST['filter']))
    	{
    		$fbytype = $_POST['bytype'];
    		$fbytopic = $_POST['bytopic'];
    		$fbyregion = $_POST['byregion'];
    
    		$fsortby = $_POST['sortby'];
    		$fview = $_POST['view'];
    		$ispodcast = false;
    
    		require('../../../wp-blog-header.php'); 
    
    		if($fsortby=="recent"):
    			global $post;
    
    		$posts = query_posts("cat=-1&order=DESC&posts_per_page=-1");
    
    		if ( have_posts() )
    		{
    			if($fview=="grid")
    			{
    				grid_style();
    				while ( have_posts() )
    				{
    					$ispodcast = false;
    					the_post(); 
    
    					if(chechcategory($post->ID,$fbytype))
    					{
    						//echo chechcategory($post->ID,$fbytype).' : '.$post->ID .' : '.$fbytype.'<br>';
    						if(chechcategory($post->ID,$fbytopic))
    						{
    							//echo chechcategory($post->ID,$fbytopic).' : '.$post->ID .' : '.$fbytopic.'<br>';
    							if(chechcategory($post->ID,$fbyregion))
    							{
    								//echo chechcategory($post->ID,$fbyregion).' : '.$post->ID .' : '.$fbyregion.'<br>';
    								if(in_category(array(7),$post->ID))
    									$ispodcast = true;
    
    								$thumbsrc = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    								?>
    
    								<div class="result-container">
    									<div class="result-title">
    										<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    									</div>
    
    									<?php 
    
    									if($ispodcast)
    									{
    										?>
    										<div class="result-image">
    											<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php echo $thumbsrc; ?>" height="100px" width="210px" alt="Link to <?php the_title(); ?>"/> </a><a class="podcast-overlay" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
    											<div class="podcast-overlay"></div>
    											</a>
    										</div>
    
    										<?php
    									}
    									else
    									{
    										?>
    										<div class="result-image">
    											<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php echo $thumbsrc; ?>" height="100px" width="210px" alt="Link to <?php the_title(); ?>"/> </a>
    										</div>
    
    										<?php
    									}
    									?>
    
    									<div class="result-text"><?php the_excerpt_max_charlength(108,$post->ID);//the_excerpt(); ?></div>
    								</div>
    
    								<?php
    							}
    						}
    					}
    				}
    			}
    			else
    			{
    				list_style();
    				while ( have_posts() )
    				{
    					$ispodcast = false;
    					the_post(); 
    
    					if(chechcategory($post->ID,$fbytype))
    					{
    						//echo chechcategory($post->ID,$fbytype).' : '.$post->ID .' : '.$fbytype.'<br>';
    						if(chechcategory($post->ID,$fbytopic))
    						{
    							//echo chechcategory($post->ID,$fbytopic).' : '.$post->ID .' : '.$fbytopic.'<br>';
    							if(chechcategory($post->ID,$fbyregion))
    							{
    								//echo chechcategory($post->ID,$fbyregion).' : '.$post->ID .' : '.$fbyregion.'<br>';
    								if(in_category(array(7),$post->ID))
    									$ispodcast = true;
    
    								$thumbsrc = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    								?>
    
    								<div class="result-container">
    									<div class="result-left">
    			                        <?php
    									if($ispodcast)
    									{
    										?>
    										<div class="result-image">
    											<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php echo $thumbsrc; ?>" height="100px" width="210px" alt="Link to <?php the_title(); ?>"/></a><a class="podcast-overlay" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
    											<div class="podcast-overlay"></div>
    											</a>
    										</div>
    
    										<?php
    									}
    									else
    									{
    										?>
    										<div class="result-image">
    											<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php echo $thumbsrc; ?>" height="100px" width="210px" alt="Link to <?php the_title(); ?>"/></a>
    										</div>
    										<?php
    									}
    									?>
    									</div>
    
    									<div class="result-right">
    										<div class="result-title">
    											<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    										</div>
    
    										<div class="result-text">
    											<?php the_excerpt_max_charlength(108,$post->ID);//the_excerpt(); ?>
    										</div>
    									</div>
    								</div>
    
    								<?php
    								}
    							}
    						}
    					}
    				}
    			}
    
    			endif;
    
    			if($fsortby=="shared" || $fsortby=="popular"):
    				$querystr = "
    				SELECT $wpdb->posts.*, CONVERT($wpdb->postmeta.meta_value,UNSIGNED INTEGER) AS Count
    				FROM $wpdb->posts, $wpdb->postmeta
    				WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id ";
    
    			if($fsortby=="shared")
    				$querystr.="AND $wpdb->postmeta.meta_key = 'total-share'";
    			else
    				$querystr.="AND $wpdb->postmeta.meta_key = 'total-count'";
    			$querystr.="
    			AND $wpdb->posts.post_status = 'publish'
    			AND $wpdb->posts.post_type = 'post'
    			AND $wpdb->posts.post_date < NOW()
    			ORDER BY Count DESC ";
    
    			$pageposts = $wpdb->get_results($querystr, OBJECT);
    			if ( $pageposts )
    			{
    				if($fview=="grid")
    				{
    					grid_style();
    					global $post;
    
    					foreach ($pageposts as $post)
    					{
    						$ispodcast = false;
    						setup_postdata($post);
    
    						if(!chechcategory($post->ID,1))
    							if(chechcategory($post->ID,$fbytype))
    							{
    								//echo chechcategory($post->ID,$fbytype).' : '.$post->ID .' : '.$fbytype.'<br>';
    								if(chechcategory($post->ID,$fbytopic))
    								{
    									//echo chechcategory($post->ID,$fbytopic).' : '.$post->ID .' : '.$fbytopic.'<br>';
    									if(chechcategory($post->ID,$fbyregion))
    									{
    										//echo chechcategory($post->ID,$fbyregion).' : '.$post->ID .' : '.$fbyregion.'<br>';
    										if(in_category(array(7),$post->ID))
    											$ispodcast = true;
    										$thumbsrc = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    										?>
    
    										<div class="result-container">
    											<div class="result-title">
    												<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    											</div>
    
    											<?php
    											if($ispodcast)
    											{
    												?>
    												<div class="result-image">
    													<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php echo $thumbsrc; ?>" height="100px" width="210px" alt="Link to <?php the_title(); ?>"/></a><a class="podcast-overlay" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
    
    													<div class="podcast-overlay"></div>
    													</a>
    												</div>
    												<?php
    											}
    											else
    											{
    												?>
    												<div class="result-image">
    													<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php echo $thumbsrc; ?>" height="100px" width="210px" alt="Link to <?php the_title(); ?>"/></a>
    												</div>
    												<?php
    											}
    											?>
    											<div class="result-text"><?php the_excerpt_max_charlength(108,$post->ID);//the_excerpt(); ?></div>
    										</div>
    
    										<?php
    									}
    								}
    							}
    						}
    					}
    					else
    					{
    						list_style();
    						global $post;
    
    						foreach ($pageposts as $post)
    						{
    							$ispodcast = false;
    							setup_postdata($post);
    
    							if(!chechcategory($post->ID,1))
    								if(chechcategory($post->ID,$fbytype))
    								{
    									//echo chechcategory($post->ID,$fbytype).' : '.$post->ID .' : '.$fbytype.'<br>';
    									if(chechcategory($post->ID,$fbytopic))
    									{
    										//echo chechcategory($post->ID,$fbytopic).' : '.$post->ID .' : '.$fbytopic.'<br>';
    										if(chechcategory($post->ID,$fbyregion))
    										{
    											//echo chechcategory($post->ID,$fbyregion).' : '.$post->ID .' : '.$fbyregion.'<br>';
    											if(in_category(array(7),$post->ID))
    												$ispodcast = true;
    
    											$thumbsrc = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    											?>
    
    											<div class="result-container">
    												<div class="result-left">
    			 									<?php
    												if($ispodcast)
    												{
    													?>
    													<div class="result-image">
    														<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php echo $thumbsrc; ?>" height="100px" width="210px" alt="Link to <?php the_title(); ?>"/></a><a class="podcast-overlay" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><div class="podcast-overlay"></div></a>
    													</div>
    
    													<?php
    												}
    												else
    												{
    													?>
    													<div class="result-image">
    														<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php echo $thumbsrc; ?>" height="100px" width="210px" alt="Link to <?php the_title(); ?>"/></a>
    													</div>
    
    													<?php
    												}
    												?>
    												</div>
    
    												<div class="result-right">
    													<div class="result-title">
    														<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    													</div>
    
    													<div class="result-text">
    														<?php the_excerpt_max_charlength(108,$post->ID);//the_excerpt(); ?>
    													</div>
    												</div>
    											</div>
    
    											<?php
    											}
    										}
    									}
    								}
    							}
    						}
    						endif;
    					}
    
    					function grid_style()
    					{
    						echo '	<style>	#search-filter-page-continer .result-container		{						float:left;			margin-left: 25px;			padding-bottom: 40px;			width: 220px; height:215px;		}		#search-filter-page-continer .result-container .result-title		{			text-transform: uppercase;			font-weight: bold;			font-size:12px;	height:32px; line-height:16px;	}		#search-filter-page-continer .result-container .result-image		{ position:relative;			margin:10px 0px;			border: 1px solid #E1DEDE;			width:210px;			height:100px;					}		#search-filter-page-continer .result-container .result-text		{			overflow:hidden;			height:57px;			width:100%;		}</style>';
    
    					}
    
    					function list_style()
    					{
    
    						echo '<style> #search-filter-page-continer .result-container{	padding-bottom: 40px;			width: 100%;			height:140px;	padding-left:30px; position:relative; display:block;	}		#search-filter-page-continer .result-container .result-left		{			float:left;			width:220px;		}		#search-filter-page-continer .result-container .result-right		{			float:left;			margin-left: 30px;	 margin-top: 10px;		width: 520px;		}		#search-filter-page-continer .result-container .result-title		{			text-transform: uppercase;			font-weight: bold;			font-size:14px;					}		#search-filter-page-continer .result-container .result-image		{ position:relative;			border: 1px solid #E1DEDE;			width:210px;			height:100px;					}		#search-filter-page-continer .result-container .result-text		{			overflow:hidden;						width:100%;			height:58px;			margin-top: 15px;		}</style>';
    					}
    
    					function chechcategory($id,$category)
    					{
    						if($category=="")
    							return true;
    						return in_category(explode(',',$category),$id);
    					}
    
    					function the_excerpt_max_charlength($charlength,$id)
    					{
    
    						$synopses = get_post_meta($id,'synopsis',true);
    						if($synopses=="")
    							$synopses = get_the_excerpt();//get_post_meta($id, 'thumbnail-copy', true);
    
    						$excerpt=$synopses;
    						$excerpt = str_replace('[quote]','',$excerpt);
    						$charlength++;
    
    						if ( mb_strlen( $excerpt ) > $charlength )
    						{
    							$subex = mb_substr( $excerpt, 0, $charlength - 5 );
    							$exwords = explode( ' ', $subex );
    							$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
    							if ( $excut < 0 )
    							{
    								echo mb_substr( $subex, 0, $excut );
    							}
    							else
    							{
    								echo $subex;
    							}
    							echo '...';
    						}
    						else
    						{
    							echo $excerpt;
    						}
    					}
    				?>

The topic ‘Help limiting posts on filter’ is closed to new replies.