Obtener la última publicación en la parte superior (orden cronológico inverso)
Frecuentes
Visto 2,014 veces
2
I am using the following but my posts are still in Chronological Order (Oldest to New). My target is to have latest post on the top. (Newest to Old)
$catquery = new WP_Query( array (
'cat'=>'27',
'post_type'=>'news',
'orderby' => "post_date",
'order' => "DESC" )
);
while($catquery->have_posts()) : $catquery->the_post();
<p class="date"> <?php the_date(); ?> </p>
<h3><?php the_title(); ?></h3>
<p> <?php the_content('Read More', FALSE); ?>
También he intentado orderby' => "date"
but no luck. How to solve this?
2 Respuestas
1
Your code is close, but there are a few problems.
'cat'
expects an int not a string so you need'cat'=>27,
- En lugar de
post_date
que necesitadate
- I'm not sure which order you need so try
ASC
ifDESC
no funciona.
Aquí está la nueva consulta:
$catquery = new WP_Query(array (
'cat' => 27,
'post_type' => 'news',
'orderby' => 'date',
'order' => 'DESC'
));
- order (string) - Designates the ascending or descending order of the 'orderby' parameter. Defaults to 'DESC'.
- 'ASC' - ascending order from lowest to highest values (1, 2, 3; a, b, c).
- 'DESC' - descending order from highest to lowest values (3, 2, 1; c, b, a).
He aquí una referencia: WP_Query
Respondido el 10 de Septiembre de 13 a las 15:09
I have already tried this, you can see last line of my question I have also tried orderby' => "date" but no luck. Thank You @graham - Shiva
@Shiva are you sure news
is a post type and not a category or tag? I know it's possible to have custom post types, but I'm just checking - graham walters
Yes news is post type wp-admin/post-new.php?post_type=news
this is the url of new news item. - Shiva
Hold on you want old -> new, you need ASC
. I misread your question. I've updated my answer - graham walters
My target is to have latest post on the top. New ---- > Old My question title is Getting Latest Post on top (Reverse Chronological Order)
Even after that I tried ASC
But still no luck Thank you - Shiva
1
your post is custom post type so use this argument:'
<?php
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'news_category',
'field' => 'id',
'terms' => '27'
)
),
'post_type'=>'news',
'order_by'=>'date',
'order'=>'DESC',
'posts_per_page'=>-1
);
query_posts($args);
while ( have_posts() ) : the_post();
?>
<li>
<p class="date"><?php echo get_the_date('F j, Y'); ?></p>
<a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php
endwhile;
wp_reset_query();
?>
Respondido el 10 de Septiembre de 13 a las 13:09
Thank You @ravi but unfortunately this 'tax_query'
is not able to fetch the posts. Am I missing any specific ID or line.. No post is being display after using this query. - Shiva
Thank You for your effort http://xxxxxx/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=27&post_type=news
he puesto 'taxonomy' => 'category'
Now post are being display on the page but new post --- > old old order is not there. - Shiva
post per page in change you display no of post and add after endwhile <?php twentythirteen_paging_nav(); ?> - Ravi Patel
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php wordpress or haz tu propia pregunta.
No debería ser
ASC
? - elclanrs@elclanrs as per my knowledge "The ASC option specifies an index maintained in ascending order; this is the default order. The DESC option can specify an index that is maintained in descending order" My target is to have latest post on the top and so on .. Thank You for your Response - Shiva
tratan
'orderby' => "date"
- Kamil@Kamil I tried the same as well but no luck - Shiva
you have a use custom post type news? - Ravi Patel