This is an inappropriate use of query_posts()
which is only for modifying the main query for the page. Additionally, even if you change your snippet to use get_posts()
, your template tags (e.g. the_excerpt()
) won’t work as get_posts()
isn’t a method of looping through posts, it just returns an array of posts.
What you want is WP_Query
. Change your first lines of code to this:
$args = array(
'post_type' => 'page',
'post__in' => array(3,5,7)
);
$my_three_posts = new WP_Query( $args );
while ($my_three_posts -> have_posts()) : $my_three_posts -> the_post();
...
Related Posts:
- When should you use WP_Query vs query_posts() vs get_posts()?
- Wp get all the sub pages of the parent using wp query
- How to query for most viewed posts and show top 5
- WP_Query vs get_posts
- Query Custom Meta Value with Increment
- Get posts by meta data OR title
- Perform query with meta_value date
- WP_Query ordered by custom field that is a date string?
- Pass the same object to multiple widgets in a template with one query
- How do you query wordpress posts using a math formula between multiple meta field values?
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Page navigation doesn’t show when query category
- How to query a custom post type with a taxonomy filter but display post type archive page?
- Change query_posts to WP_Query in page but does not work
- Custom Query num_rows returns wrong amount
- Slow page loads due to WordPress Core Query
- Query Page Content From Theme Options?
- How can I override one post and make it display content for another post?
- Include current post into loop
- Filter post query to only show direct children of category
- Should I reset $wp_query?
- Why doesn’t my WP Meta Query return any results?
- Filter products on category AND tag
- pre_user_query vs pre_get_posts
- Get posts that match defined arrays of tags
- I need query_posts() to order results first by a meta value and then by post ID
- How to show post title in content editor in backend?
- My entry results are not consistently alphabetized
- Merge two queries and remove duplicate
- Ordering Posts by parent category, name ascending
- Optimising specific Query with ACF meta objects
- How to organize a WP_Query’s list of posts by category and display category title?
- When should you use WP_Query vs query_posts() vs get_posts()?
- How to query post ids liked by the Author
- WordPress Query showing multiple titles
- Query Posts by date range with fixed beginning and end
- custom query to get posts
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Query Posts in a Predefined Order
- How to uniquely identify queries?
- Problem with ‘post__not_in’
- How to make an activities stream mixing posts and comments?
- How to query for a week using key => value WP_Query argument notation?
- SQL query equivalent to WP User Query
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- meta_query on a date range using an array of values
- How to detect custom query inside `posts_where` hook?
- Is temporarily overwriting $wp_query a bad idea?
- Query Set Order By Author
- How to Loop within a Loop (Display Children and then Grandchildren)
- How can I pick a single post from the latest 3?
- How to orderby meta_value_num with dollar ($) sign
- How to correctly pass values to wpdb->prepare()?
- Query with custom taxonomy not working
- Improving WP_Query for performance when random posts are ordered
- Query posts by specific word on title
- Query: offset post list, unless it’s a specific category
- Tricky WP Query
- Using ajax with paging and a custom sub-query
- Fetch Record based on meta key dates
- add active class based on permalink and url
- WP_Query with ‘rand’, but equal number of posts from the taxonomy terms given
- Filtering out child category posts from parent category archive not working
- Sort WordPress Posts Meta value by Week not Day
- Advanced WP Query and/or
- 2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?
- Get multiple users with meta value in one query and populate WP_User class
- Query for first 3 posts to change the look and feel
- How to create custom query by keyword in post title?
- Query where ANDing slug values not working
- How to filter query loop block with a search string from the query parameters
- How can I comment comma-separated array values?
- How to use ‘WP_Query’ or ‘query_posts’ to display content in a descending order
- 2 queries with counters
- How to SQL query posts IDs by categories AND authors?
- Multiple Query_Posts
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- Query multiple post types, but different order for each
- query hook parse_tax_query function takes no effect
- Duplice post with standard WP loop – fixed by using query_posts() instead
- Any way to use FETCH_KEY_PAIR with $wpdb?
- Custom query for custom post type not getting correct post ID
- How to get_comments() ordered by date and parent?
- Show 5 posts and than 3 posts offset with pagination
- Adding Category in WP_Query Not Working
- how to show more than 1 post into three columns query
- Seach and categories not working when ignoring sticky posts in main loop
- posts_per_page increment additional post
- Fetch only categorized posts
- Custom pagination (Title, date and teaser)
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- get contents and permalink from a specified page
- Showing posts from 4 categories along with all latest posts
- Help in query for list links
- WordPress pagination returns the same posts
- WP Query – Show custom posts only if user contain some user meta
- Show number of posts AND number on current page (cannot make it work)
- Advanced Search – Is this possible?
- new WP_Query with order args – no more distinction between categories