Home › Forums › WordPress › Enqueue Scripts and Styles › WP-query a simple query example.
- This topic has 0 replies, 1 voice, and was last updated 8 years, 4 months ago by Layer7web.
Viewing 0 reply threads
-
AuthorPosts
-
-
August 15, 2016 at 10:02 pm #2395
Layer7webKeymasterPHP1234567891011121314151617181920212223242526272829$args = array('post_type' => 'post','post_status' => 'published','category_name' => 'announcements','posts_per_page' => 1,'order_by' => 'date','order' => 'DESC',);$the_query = new WP_Query( $args );ob_start();// The Loopif ( $the_query->have_posts() ) {echo '<ul>';while ( $the_query->have_posts() ) {$the_query->the_post();echo '<li>' . get_the_title() . '</li>';}echo '</ul>';/* Restore original Post Data */wp_reset_postdata();} else {// no posts found}$output = ob_get_contents();ob_end_clean();return $output;
-
-
AuthorPosts
Viewing 0 reply threads
You must be logged in to reply to this topic.
Comments are closed.