Jump to content

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


iarp

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 } ?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.