Skip to content

Instantly share code, notes, and snippets.

@ericpedia
Created July 15, 2011 18:55
Show Gist options
  • Save ericpedia/1085282 to your computer and use it in GitHub Desktop.
Save ericpedia/1085282 to your computer and use it in GitHub Desktop.
How to change this foreach into a normal loop that can use, e.g., the_title()?
// http://wordpress.stackexchange.com/questions/23088/how-to-change-a-custom-query-into-a-standard-loop
$totalposts = $wpdb->get_results($querystr, OBJECT);
$wp_query->request = $querystr . " LIMIT " . $ppp . " OFFSET " .$offset;
$results = $wpdb->get_results($wp_query->request, OBJECT);
foreach ($results as $result) { /* instead of this I want something that would work like while ( $the_query->have_posts() ) : $the_query->the_post(); */
$offset++;
$output .= '<a href="'.get_post_permalink($result->ID).'">' . $result->post_title . ' (' . $result->post_date . ')</a><br>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment