The following 3 parameters will give you the posts in Ascending order from the date it was published (i.e The older posts will be shown first)
‘post_status’ => ‘publish’, ‘orderby’ => ‘publish_date’, ‘order’ => ‘ASC’
When you change the order to DESC you will get the posts in Descending order from the date it was published (i.e The latest posts will be shown first)
‘post_status’ => ‘publish’, ‘orderby’ => ‘publish_date’, ‘order’ => ‘DESC’
<?php
$postsPerPage = 10;
$page = 1;
?>
<?php
$query = new WP_Query(array(
'cat' => 4,
'post_status' => 'publish',
'orderby' => 'publish_date',
'order' => 'ASC',
'paged' => $page,
'posts_per_page' => $postsPerPage));
?>
Related Posts:
- How to paginate wordpress [gallery] shortcode?
- What kind of object type is WP_Query?
- Shortcode returns escaped HTML tags
- WP_Query in a shortcode
- ‘&’ causes an error in my shortcode when I list the content of the page
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- How to retrieve current page WP_Query arguments?
- wp_query add arguments using array_push if variable met
- Category attribute not working in custom shortcode
- How to get all child pages in their parent page?
- Database Queries Optimization with new WP_Query
- Orderby is working with one query but not with other
- Shortcode for latest -not expired- posts
- Gallery shortcode numerical sorting
- How to filter a query by date in a shortcode?
- How should I approach changing the template & $query as part of a shortcode’s execution?
- Shortcode Not Working in Slider When Added To Post Title
- Shortcode for custom query not returning results when attributes are added
- How to Display Shortcode in the correct location, currently displaying before content after Page Title?
- WP_query only displays one of my custom post type entries
- Assign a minimum result count for WooCommerce query shortcodes?
- Using a Shortcode to List Posts from Multiple Categories
- embedding shortcodes in php template
- How to get specific string in explode array?
- Trouble passing attribute into shortcode function
- Woocommerce Shortcode which displays a table with product data
- WP Query by 4 different taxonomies
- create custom shortcode wp and put php code in
- How to display a post(by id) along with css in a page?
- Shortcode attributes causes 500 error after updating the page
- pages shortcode filtering by category
- WP_Query & shortcode : Return 3 articles from a category WordPress
- Query by Category and Custom Field – Shortcode
- How to take parameters from a function and make them editable as attributes in a shortcode
- How to modify WP Query to target the first most recent post to adjust content
- Object of class WP_Query could not be converted to int inside shortcode
- How can I create another instance of my custom shortcode
- Get Current CPT taxonomy category in shortcode
- Custom shortcode not displaying categories and correct date
- return wp query results in a shortcode
- More efficient query to display posts in same sub-category?
- Having Trouble Running Query From Shortcode Using Tribe’s Events Plugin
- shortcode using multiple WP_Query’s with multiple category names not fully functional
- Shortcode does not display pagination [duplicate]
- How to write a query-function as a query-shortcode?
- shortcode with $atts with strange results
- WP_query shortcode inside acf Repeater breaks the repeater loop
- How to prevent WP query searching in executed shortcodes
- Find out total number of pages in global query on archive page?
- Is it possible to completely stop WP_Query retrieving posts?
- Pagination returns 404 after page 20
- Make a WP Query search match exactly the search term
- Make loop display posts by alphabetical order
- Displaying several specific pages using WP_Query()
- Why does pagination always break when used on any form of a home page?
- Multiple orderby parameters in pre_get_posts() action
- Select posts wich has no relationship in custom taxonomy
- Finding the next 5 posts
- How to wp_query posts with ajax
- post thumb nail
- Filter by title content and meta key at the same time
- Get all remaining posts after a particular post id
- Is it possible to create a shortcode that will query a post based on taxonomies?
- What is considered a default query for the request filter?
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- Improve wp query perfomance on large db
- If two first numbers exist in wp_meta_query value
- Two different conditions with a single WP_Query
- How to query for posts without a post_format
- Function get_queried_object() return NULL in custom taxonomy
- Search pages that are a child of the current page
- WordPress search posts by author name with autocomplete
- WP Query using tax_query & meta_query
- How to control a common terms list from one place?
- Exclude Category filter from Portfolio section
- Search form not working with custom query?
- date_query seems to be ignored by wp_query
- Query Vars Not Set in Main Query
- Order post type by sum of two custom fields
- Need to add onclick javascript at backend of my wordpress site
- How do you determine if a result in a search query is a post or a page?
- Order WP_Query results by meta key value in custom query
- Display recent posts on another site
- WP_Query for products always returns empty
- Issue with data array format
- WP_Query custom post with by general tags
- Why are my wp_query args being ignored if post_type = CPT
- Multiple Arrays for Custom Post Query using Boostrap accordions and ACF repeater fields
- WordPress Query optimaization for slow query
- WordPress – just refresh blog archive by new query
- How to pass a php variable to js within a template?
- Meta query doesn’t remove placeholder escape before query
- Custom query: post__in parameter causes query to be empty
- Show subscriber id in loop
- WP_Query using meta_query with LIKE doesn’t return what it should
- How to organize a WP_Query’s list of posts by category and display category title?
- How to Query Updated Post in WordPress
- Query_vars not working for me
- Query posts only shows 1
- Why am I getting no results of a query placed after another query?