Jump to content

Archived

This topic is now archived and is closed to further replies.

iarp

[SOLVED] Wordpress, 2 querys one the same page, need to clear the first

Recommended Posts

 

 

I have these 2 query's each grab certain types of posts according to their category

SELECT post.ID, post.post_title, terms.name FROM $wpdb->posts AS post, $wpdb->terms AS terms, $wpdb->term_relationships AS tr WHERE (post.ID = tr.object_id) AND (tr.term_taxonomy_id = terms.term_id) AND terms.name = 'Newsletter' AND post.post_status = 'publish' AND post.post_date_gmt < '$today' AND post.post_type != 'page' ORDER BY post.post_date DESC LIMIT 5")) { ?>

 

and

SELECT post.ID, post.post_title, terms.name FROM $wpdb->posts AS post, $wpdb->terms AS terms, $wpdb->term_relationships AS tr WHERE (post.ID = tr.object_id) AND (tr.term_taxonomy_id = terms.term_id) AND terms.name = 'Events' AND post.post_status = 'publish' AND post.post_date_gmt < '$today1' AND post.post_type != 'page' ORDER BY post.post_date DESC LIMIT 10")) {

 

Both are basically the same exact one terms.name = '' says Newsletter and ones Events.

 

Having both of those query's in my sidebar.php page... the actual < a > link part is fine and works, but the_title() displays the last result of the first query

 

Any insight what i can do to clear the_title or something. I've tried

<?php $wpdb->flush(); ?>

everything and it doesn't work... even right after the query themselves.

 

This is the output code:

<?php
			$today1 = current_time('mysql', 1);
			if ( $eventposts = $wpdb->get_results(
				"
				SELECT post.ID, post.post_title, terms.name
				FROM $wpdb->posts AS post, $wpdb->terms AS terms, $wpdb->term_relationships AS tr
				WHERE (post.ID = tr.object_id) AND (tr.term_taxonomy_id = terms.term_id) AND terms.name = 'Events' AND post.post_status = 'publish' AND post.post_date_gmt < '$today1' AND post.post_type != 'page' ORDER BY post.post_date DESC LIMIT 10")) { ?>
			<ul>
				<?php
				foreach ($eventposts as $post1) {
				if ($post1->post_title == '')
				$post1->post_title = sprintf(__('Post #%s'), $post1->ID);
				echo "<li><a href='".get_permalink($post1->ID)."'>";
				the_title();
				echo '</a></li>';
				} ?>
			</ul>
			<?php } else { ?>
			<ul>
				<li>No Events at this time</li>
			</ul>
			<?php } ?>

 

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.