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
- How to create a three column blog layout with a single query and with three different classes?
- database query with more than a couple meta hangs and doesn’t complete
- Query post with meta value in set of values
- get_template_part causes 500 error
- Finding WordPress Posts assigned to multiple categories
- Does meta_value (array) work with ‘orderby’?
- wp_query is showing posts from other categories
- Get posts in taxonomy randomly
- Page navigation doesn’t seem to work when I add offset?
- is_404() – where does this get set?
- Max Posts and Memory Limit
- WordPress | WP_Query does not return anything with s=a
- WP_Query Pagination
- WP_Query orderby
- Using Ajax and WP_Query to load more posts on category page fails
- I have problems with the search query using multiple post types
- How to check if logged in user have pending custom post?
- How can I re-query post_type and rewrite the url?
- Different query result on local and server
- meta_query compare > not working
- How can I show only last year posts in wordpress archive?
- WP_Query about meta_key and its array value
- Query string order by custom field
- Related Post by Tags Code
- I can’t get post based on its postmeta value and key
- Change database image location for transportability
- Combine Tax Archive and Meta_Query in WP_Query
- Get posts by birthday
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Paginate nested query of child posts
- Display three sequential posts on each page load, without repeating previous
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Find by post_meta, then sort by post_meta, then sort by date (wp_posts)
- Optimising amount of calls to custom fields
- Issue in If else condition [closed]
- Pagination not working with WP_QUERY
- Custom Content Slider stop duplicate
- Extract video content from post to display on front page
- Sort Posts with custom meta key by default which is currently set as optional
- wp_query pagination links producing 404
- How return normal search result using wp_ajax action for wordpress
- Pagination problem with multiple loops on the same page
- Carousel slider with WP_Query to show 3 posts on each slide
- how to use transient method?
- WP_Query – meta fields numeric
- How to query posts from single post format on Genesis framework
- How to replecate the _fields parameter in custom REST api endpoint
- I want to capture the last day’s (today) posts in a category in the numbered order in acf
- SQL command to delete bulk WP post specific
- Removing filename searches when searching attachments
- WordPress WP_Query custom order_by post_type functionality
- $wpdb->get_results() into foreach() returns always the word “Array” on top of the list . How to get rid of?