• Hey,

    I have made this page https://www.ramobiler.dk , and everything is working fine so far, but in the car page (Biler), the car posts are showing twice. Biler page refers to a plugin called Car Listing, but I dunno which part to edit to stop the multiple pages. All though the content itself isn’t duplicated, only the links showing to each car is showing two or three times.

    <?php
    /*
     Info for WordPress:
     ==============================================================================
     Plugin Name: Car Listing
     Description: Car Listing project
     Version: 0.1
     Author: Fedmich
     Author URI: https://fedmich.com/works/
    */
    
    ?>
    <?php
    // Add Shortcode
    function car_listing() {
    	//	Year Color Mileage Price
    	define('CAR_LISTING_PLUGPATH', get_option('siteurl').'/wp-content/plugins/'.plugin_basename(dirname(__FILE__)).'/');
    
    	$search = empty( $_GET['search'] ) ? '' : $_GET['search'];
    	?>
    	<link href="<?php
    		echo plugins_url( 'fedmich-car-listing.css', __FILE__ );
    	?>" rel="stylesheet" type="text/css" media="all" />
    	<script type="text/javascript" src="<?php
    		echo plugins_url( 'fedmich-car-listing.js?v2', __FILE__ );
    	?>"></script>
    	<?php
    		$no_photo = plugins_url( 'no_photo.png', __FILE__ );
    	?>
    	<div class="fedmich_car_listing grid">
    		<div class="listing_navigation">
    			<div class="listing_sort">
    				Sort:
    				<a href="<?=url_current_set('sort','car_make');?>">M?rke</a>
    				<a href="<?=url_current_set('sort','car_year');?>">?r</a>
    				<a href="<?=url_current_set('sort','car_color');?>">Farve</a>
    				<a href="<?=url_current_set('sort','car_mileage');?>">Kilometer</a>
    				<a href="<?=url_current_set('sort','car_price');?>">Pris</a>
    			</div>
    			<div class="listing_search listing_right">
    				<?php
    					$url_page_form = '//' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
    					if( strstr($url_page_form, '?') ){
    						$url_parsed = parse_url($url_page_form);
    						$url_page_form = $url_parsed['path'];
    					}
    
    				?>
    				<div class="listing_searchbox">
    					<form name="" action="<?=$url_page_form;?>">
    						<input type="text" id="search" name="search" value="<?=$search;?>" placeholder="Search..." required />
    					</form>
    				</div>
    				<div class="listing_modes">
    					<a href="#" rel="grid" id="mode_grid" class="active_mode">GRID</a>
    					<a href="#" rel="list" id="mode_list">List</a>
    				</div>
    			</div>
    			<div class="clear"></div>
    		</div>
    		<div class="clear"></div>
    
    		<div class="listing_posts">
    	<?php
    		$post_limits = 50;
    		global $wpdb;
    
    		/*
    		$query = "posts_per_page=$post_limits";
    		if( $search ){
    			$query .= "&s=" . urldecode( $search );
    		}
    		*/
    
    		$meta_key = empty( $_GET['sort'] ) ? '' : $_GET['sort'];
    		if(! empty($meta_key) ){
    			//$query .= "&meta_key=$meta_key&orderby=meta_value_number&order=ASC";
    			//$query .= "&meta_key=$meta_key";
    		}
    
    		if( $meta_key ){
    			$sq_metakey = " AND ( $wpdb->postmeta.meta_key = '$meta_key' OR $wpdb->postmeta.meta_key IS NULL ) ";
    		} else {
    			$sq_metakey = '';
    		}
    
    		if( $search ){
    			$sq_search = " AND $wpdb->posts.post_title like '%$search%' ";
    		} else {
    			$sq_search = '';
    		}
    
    		$sql = "
    		SELECT * FROM $wpdb->posts
    		LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    		LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    		LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    		WHERE $wpdb->posts.post_type = 'post'
    		-- $wpdb->term_taxonomy.taxonomy = 'category'
    		-- AND $wpdb->term_taxonomy.term_id = 13
    		AND $wpdb->posts.post_status = 'publish'
    
    		$sq_metakey
    		$sq_search
    
    		ORDER BY
    		ISNULL( $wpdb->postmeta.meta_value   )
    		, $wpdb->postmeta.meta_value
    
    		limit 50
    		";
    
    		$pageposts = $wpdb->get_results( $sql, OBJECT);
    		//var_dump($meta_key);
    		//query_posts( $query );
    		global $post;
    	?>
    	 <?php if (! $pageposts){ ?>
     	<div class="listing_none">
    		No cars found based on your Sort/Search...
    	</div>
    	 <?php } else { ?>
    		<ul>
    	  <?php foreach ($pageposts as $post){ ?>
    		<?php setup_postdata($post); ?>
    
    		<li class="">
    
    			<div class="car_thumbnail">
    			<?php
    			if ( has_post_thumbnail() ) {
                	?>
                	<a href="<?php echo the_permalink(); ?>"><?php
    				the_post_thumbnail(array(200,150));
    				?></a><?
            	}
    			else{
    				?>
    				<a href="<?php echo the_permalink(); ?>"><img src="<?=$no_photo;?>" alt="" /></a>
    				<?php
    			}
    			?>
    			</div>
    			<div class="listing_fields">
    				<?=fed_get_custom('car_make', 'M?rke');?>
    				<?=fed_get_custom('car_year', '?r');?>
    				<?=fed_get_custom('car_color', 'Farve');?>
    				<?=fed_get_custom('car_mileage', 'Kilometer');?>
    				<?=fed_get_custom('car_price', 'Pris');?>
    			</div>
    			<div class="clear"></div>
    			<h2 class="post_title"><a href="<?php echo the_permalink(); ?>"><?php echo get_the_title();?></a></h2>
    			</li>
    			<?php
    		}
    		?>
    		</ul>
    		<?php
    		}
    
    		wp_reset_query();
    	?>
    
    		<div class="clear"></div>
    		</div>
    		<div class="clear"></div>
    	</div>
    	<?php
    	// Code
    	return '';
    }
    
    function fed_get_custom( $fld , $fld2 ){
    	static $custom_fields;
    	if(empty($custom_fields)){
    		$custom_fields = get_post_custom();
    	}
    	$val = get_post_custom_values( $fld );
    	if(! empty( $val )){
    		?>
    		<div class="val">
    			<?=$fld2;?>: <?=$val[0];?>
    		</div>
    		<?php
    	 }
    }
    
    function url_current_set( $param, $value){
    	static $url_current;
    	if(empty($url_current)){
    		$url_current = '//' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
    	}
    
    	if( strstr($url_current, '?') ){
    		$url_parsed = parse_url($url_current);
    
    		$found = false;
    		$segments = explode('?', $url_current );
    		$parts = explode('&', $segments[1] );
    		foreach ( $parts as $ctr => $part){
    			$vals = explode('=', $part );
    			if( $vals[0]==$param ){
    				$parts[$ctr] = "$param=$value";
    				$found = true;
    			}
    		}
    		if( $found ){
    			$segments[1] = implode('&', $parts );
    			$url_page = implode('?', $segments);
    		}
    		else{
    			$url_page = $url_current . "&$param=$value";
    		}
    	}
    	else{
    		$url_page = $url_current . "?$param=$value";
    	}
    	return $url_page;
    }
    
    add_shortcode( 'CAR_LISTING', 'car_listing' );
  • The topic ‘Multiple posts’ is closed to new replies.