Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

SpidermanPuddin on "Custom Select Query doubles posts"

$
0
0

Custom Select query will SOMETIMES double the post. Meaning it'll display the same post twice, consecutively. It only does it on certain term ids. Here's the query

$querystr = "
			SELECT COUNT(ID)
			FROM $wpdb->posts
			LEFT JOIN $wpdb->postmeta AS date_value
				ON($wpdb->posts.ID = date_value.post_id
				AND date_value.meta_key = 'date_value')
	  		INNER JOIN  $wpdb->term_relationships
	              ON (wp_posts.ID = $wpdb->term_relationships.object_id)
	  		INNER JOIN  $wpdb->term_taxonomy
	              ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
	        INNER JOIN  $wpdb->terms
	              ON ($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
			WHERE $wpdb->posts.post_status = 'publish'
				AND $wpdb->posts.post_type = 'custom_post'
				AND date_value.meta_value >= '" . date('Ymd') . "'
				AND $wpdb->terms.term_id IN ( $term->term_id )
	";
	$result = mysql_query($querystr) or die(mysql_error());
	// Print out result
	while($row = mysql_fetch_array($result)){
		$gs_count = $row['COUNT(ID)'];
	}
	unset($querystr);

I've only been able to fix this by deleting the post(s) and republishing them.


Viewing all articles
Browse latest Browse all 8245

Trending Articles