$query = new WP_Query( $args );
if ( $query->have_posts( $query->have_posts()) ) : while( $query->have_posts()) :
$query->the_post();
global $post;
switch ( $query->current_post ) {
case 0 :
// first post object is in var $post;
echo 'The first post title is ' . $post->post_title;
break;
case 1 :
// because we are insed the loop we can use all the post template tags
echo 'The second post title is ' . get_the_title();
break;
....
}
endwhile; endif;
wp_reset_postdata();
Related Posts:
- Using a custom WP_Query with get_template_part loop
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- How to make WP_Query ‘post__in’ accept an array?
- WP_QUERY Get posts by category and similar name (Like)
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- Is it possible to wrap Geo Location search around WP_Query?
- WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given
- Merging multiple wp_query objects
- Query causing load because of SQL_CALC_FOUND_ROWS post counting?
- Using custom meta_query with relation not working as expected
- Nested query inside Logical operator OR not working in meta_query
- SQL Statement generated by WP_Query not producing expected results
- Only show first post to match certain criteria within WP_Query
- What is an efficient way to query based on post_meta?
- Best practice for multiple queries on page
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Pagination wont work with search results template [duplicate]
- Pagination Not working on Home Page with 2 Query
- WP_Query in a shortcode
- Exclude post on loop by multiple meta key value
- How to use WP_Query to filter posts modified after a specific date
- Select random post every day
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Include Sticky Posts with Custom Query
- Order WP Query posts by custom order calculated from post meta values
- How to query for custom field within Gutenberg block from outside of that post? [closed]
- WP_Query mixe post and page attributes
- post thumbnail not showing up with shortcode
- Wp query orderby ‘title’ doesn’t work
- How do you Query posts with nothing in common?
- Meta query with JSON value
- Prevent duplicate post from dynamic multiple loops
- Get meta info related to current post
- When to add_filter() to Custom Query
- if/else on custom query gives 200 OK when condition not met?
- Creating arguments from loop for WP_Query meta_query
- Select from wp_post and multiple meta_value from wp_postmeta
- Can I count matches without doing a query?
- Store sticky post’s ids in a transient
- How to use MySQL’s MATCH AGAINST in WP_Query?
- Using meta_query with multiple keys and compare values
- Woocommerce query all products and categories
- Add “Category” to Mysql Query
- Can I set my WP_Query to be a Main Query?
- How to use external API content in place of WP posts using $wp_query?
- Make a page return false to is_single() and true for is_post_type_archive() before wp_enqueue_scripts
- Is it possible to set specific posts to show first in a query?
- wp_query args adding muitiple tax_querys
- WP_Query posts with comments only
- Default permalink structure causing Notice: Undefined property: WP_Query::$post
- How to check the array values, what WP_Query has brought to me?
- How to Order a list of taxonomies? orderby?
- How do I check if an article is popular this week?
- Get posts that do not have the same tags as current
- queried_object using pre_get_posts gets notices and warning
- post_parent don’t work and return 0 page
- Exclude a Woocommerce product from WP_Query
- create metabox to activate slider
- Expecting statement error from php loop using ACF plugin
- Get specific ACF key and value from all posts – no access to DB
- How do I sort this custom list of sticky posts
- Query only displays one page_id
- How to exclude a category name from showing?
- WP_Query will not display draft posts
- All Posts Have The Same Comments
- Trying to get property of non-object in: $wp_query
- I am officially missing something about transient posts
- Register Taxonomy – What is `query_var`?
- Get Post ID as a separate RSS feed item
- how to retrieve WP_Query without ordering by date [duplicate]
- Query post and sort by custom value calculated with custom field on cpt
- Related posts by current posts child category
- Block internal search queries with pre_get_posts and regex rules
- WP_Query() not working as expected
- How to sort store location by specific category order in WP store locations
- Is it possible to give a classname to specific comments in the WordPress admin?
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- Trouble with serialized metadata
- Is there documentation for objects returned by WP_Query?
- How to upload 3 attachments to current post?
- Custom post type loop error: Trying to get property of non-object
- Search Field that allows options of “Match any keyword” or “Match all keywords”
- WP_Query for posts that have postmeta assigned to a taxonomy
- Getting the last X posts, but in ascending order of time
- Help displaying related categories
- How to fix pagination for custom loops on front-page.php
- Show more than one post on the main page excluding certain category
- How to make a wordpress loop file that displays posts based on certain conditions
- WP_Query with MetaQuery issue
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- How to sort a WP_Query array by post_name after an array_merge();
- Comment count same for every post in homepage WP_Query
- How do I display posts with specific value in a custom field into my loop?
- Orderby Meta Value and Query from Meta Query
- WP Query to order posts by multiple meta fields
- Order by multiple meta keys on wordpress
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- WP_Query breaks pagination
- wpdb LIKE request shows all database data
- WordPress extremely slow when using get_posts with multiple meta_query relations