if you want to show only 2, put it as a value, like so:
'posts_per_page' => 2
For the newest posts, you need to change the sort using the order and orderby params:
'orderby' => 'date',
'order' => 'ASC'
Details about orderby params here: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
Also, you should avoid the query_posts use. Except if you are using a part of your page only, I believe that’s the case.
On Codex you can see on description about avoiding the query_posts use.
Check this video where a WP Core developer talks about query_posts and so on: http://wordpress.tv/2013/03/15/andrew-nacin-wp_query-wordpress-in-depth/
Related Posts:
- How to store the_title() into a variable to reutrn the value, not just echo it
- Need to get specific data from array
- Create an array from an array
- Check if term object is in array
- get a simple array of all of the term names that exist in all taxonomies
- Populate dropdown with Child Pages based on Parent Page chosen
- foreach loop still echoes array
- Checking array against author id in loop
- Alter required message using comment form api
- meaning of (array)function()
- wp_force_remove_style’ not found
- How to fix this warning:call_user_func_array() expects exactly 2 parameters, 1 given in D:\wamp\www\…….\wp-includes\class-wp-hook.php on line 286
- Filtering a function’ output for a new continued function
- How to use array in function to get only value I want
- Warning: in_array() null given in PHP function
- Loop over Array and get the distinct ids
- If Array Values Match Another Array’s Values, Then
- How to make sure relative URL works when site is not on root domain?
- Custom functions for string data calculations
- Store custom field’s multiple values in one user meta key
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Display posts using post ID’s in an array
- Page returning ID from array, how to return the correct values for post in acf wordpress
- Display a post based on its metabox selection
- Showing all post from all post type in admin backstage
- Custom WordPress Function – Adding items from Foreach Loop into an array and Updating Field based on array of IDs (ACF + WooCommerce)
- Replace block content with an array
- Error Warning: Declaration of description_walker::start_el after PHP upgrade [duplicate]
- Mega Menu Walker
- Autoloading in Child Theme
- How to add a class to the attachment images
- How to correct schedule my event weekly with wp_schedule_event()
- Execute a shortcode when clicking on a image
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- Looping through WP_Post Object
- Generate an array of parent/child page IDs, based on parent page name
- How do I output a database option that is an array into a get_posts array?
- Change logo based on incoming domain
- Count the number of times the search form template gets included on a page
- PHP code inside shortcodes
- How do I display a user’s previous orders as a select box option on a product?
- Remove meta description on certain pages
- Image media upload metabox
- How to combine wordpress_logged_in cookies in one cookie?
- Two Different Links for Same Product – WooCommerce [closed]
- Woocommerce related product text
- esc_html_e() is not translating string in wordpress [closed]
- Limit 1 global comment per minute
- Remove echo from shortcode
- Is there a way to conditionally check whether a WordPress post title is empty?
- Copyright info change – Corporate Plus Theme PHP [closed]
- Inject class in body when particular page template is used
- Echo a function inside a function
- Advanced Custom Fields – display label and value only if value entered
- Use WordPress function in php file
- is_user_logged_in() not working in AJAX validation call
- Pagination on Custom Post
- how to save checkbox data for custom setting?
- How to keep the capability of users and disable Gutenberg editor in WordPress?
- Add product to cart for user – WC()->cart->add_to_cart [closed]
- How to create a field in customize and show that in header.php?
- Enqueing External JS on the remote server JS
- iframe not showing in content on blog page
- Get the name of menu item with wp_nav_menu
- How to add aria role and schema markup to custom walker container
- PHP Output also in Child theme, but different
- writing an unique php function to be used on my website
- How to prevent a function from running based on host (ie web vs local)?
- How to change the author box selection on a post to a custom taxonomy
- Output product category link from WP_Query
- Adding onload to body for certain pages
- Delete images from media library when user deletes an image from ACF Gallery
- Reject all malicious URL requests functions.php
- How to send a php var to jQuery Ajax call with two different file
- Change wordpress’ database data using ajax – how to get current user id?
- Create an array with all the links of the years’ archive (of a custom post type)
- not outputting medium size image URL
- Best way to use variables in multiple functions?
- Notice: Undefined variable
- Cannot fetch posts with certain ‘product_cat’. WP_Query is empty
- How to override WooCommerce Order Item Meta with data from Cart?
- Detect what link user clicks and Redirect to a specific page for logged in users only
- Offset with ajax load more posts duplicates
- get_category_parents to array
- Need help with PHP functions
- WordPress styling recent post
- Break a WordPress function to run in patches and re-continue
- syntax error unexpected ‘}’ at 364 line
- get_post_meta no longer working
- Highlight posts currently being edited on multiple editor site?
- Shortcode to include PHP file, pass various parameters to include?
- Why can’t I include echo inside a variable? [closed]
- Assign new post author IF another user in custom field on post transition
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- How do I change the Go To Categories link in the term_updated_messages
- WooCommerce – Show ‘Sales’ badge on variable products where only some variations have sales price [closed]
- Understanding responsive imagery
- How to get meta box labels?
- How to group by column a and sum column b and c in a php array
- Tags being Inserted in html from plugin PHP not passing through the_content