WordPress.org

Ready to get started?Download WordPress

Forums

"Recent Posts" not finding any posts (2 posts)

  1. Adriandc
    Member
    Posted 1 year ago #

    Hi , I created a widget using these instructions...
    http://blue-anvil.com/archives/create-a-wordpress-recent-posts-widget/

    It all seems to be set up fine only its not actually receiving any posts.

    Here is the code specfic to getting posts, just wondering is there anything wrong with this?
    Apologies as im still only learning this stuff..

    // GET POSTS
    			global $wpdb;
    			$sql = 'select DISTINCT * from '.$wpdb->posts.'
    			INNER JOIN (select * from '.$wpdb->post2cat.'
    			INNER JOIN '.$wpdb->categories .' ON '.$wpdb->post2cat.'.category_id = '.$wpdb->categories .'.cat_ID)
    			as A ON '.$wpdb->posts.'.ID = A.post_ID
    			WHERE (A.cat_ID NOT IN ('.$exclude.'))
    			AND '.$wpdb->posts.'.post_status="publish"
    			AND '.$wpdb->posts.'.post_type="post"
                            GROUP BY ID
    			ORDER BY '.$wpdb->posts.'.post_date
    			DESC LIMIT 0,'.$show.';';
    
    			$posts = $wpdb->get_results($sql);
    
    // start list
    			echo '<ul>';
    				// were there any posts found?
    				if (!empty($posts)) {
    					// posts were found, loop through them
    					 foreach ($posts as $post) {
    
    							// format a date for the posts
    							$post->post_date = date("F j, Y",strtotime($post->post_date));
    
    							// if we want to display an excerpt, get it/generate it if no excerpt found
    							if ($ex) {
    								 if (empty($post->post_excerpt)) {
    									 $post->post_excerpt = explode(" ",strrev(substr(strip_tags($post->post_content), 0, 100)),2);
    									 $post->post_excerpt = strrev($post->post_excerpt[1]);
    									 $post->post_excerpt.= " [...]";
    								 }
    							}
    
    							//output to screen
    							echo '<li>
    							<a class="post" rel="bookmark" href="'.get_permalink($post->ID).'"><span class="inner">
    							<strong class="title lifestyle">'.$post->post_date.' - '.$post->post_title.'</strong>';
    
    							if ($ex) echo '<br />'.strip_tags($post->post_excerpt);
    
    							echo '</span></a></li>';
    					 }
    				} else echo "<li>No recent Posts</li>";
    		// end list
    		echo '</ul>';
  2. Adriandc
    Member
    Posted 1 year ago #

    think I realised whats wrong, post2cat doesnt exist anymore

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.