Home › Forums › WordPress › Enqueue Scripts and Styles › WP-query a simple query example.
Tagged: WP-query, pages, posts, wordpress
$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 Loop if ( $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;
You must be logged in to reply to this topic.