Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 607 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WP_Query('orderby=post_date') not working with wordpress

#1
`WP_Query('orderby=post_date')` is not working with wordpress.

how do I sort my posts in descending order?
Reply

#2
WP_Query('orderby=date&order=DESC')
Reply

#3
To order by the modification date you have use `orderby=modified`.

WP_Query( 'orderby=modified&order=DESC' )

See [the documentation][1] for more possible values.


[1]:

[To see links please register here]

Reply

#4
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));
?>
Reply

#5
Try this



$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
"post_type" => "post",
"post_status" => "publish",
"paged" => $paged,
"orderby" => "date",
"order" => 'ASC'
);
WP_Query($args);
Reply

#6
If you are using `PostTypesOrder plugin` it might globally modify your query, in order to avoid this behaviour to particular post type

add_filter('pto/posts_orderby/ignore', 'theme_pto_posts_orderby', 10, 3);

function theme_pto_posts_orderby($ignore, $orderBy, $query)
{
if( (! is_array($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'post') ||
(is_array($query->query_vars) && in_array('post', $query->query_vars)))
$ignore = TRUE;
return $ignore;
}
Reply

#7
Just one more note, I pulled my hair out because all the time I was getting the same items in the list, than I realized I needed to add:

'ignore_sticky_posts' => true,

I hope someone else will notice this before I did.
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through