php - Wordpress Order by date on custom post type not display on archive page
Get the solution ↓↓↓I have a custom post type called trivias and i created a archive page with the following code in wordpress. The posts displays but not in the order. I need it with date and desc ordering. When i changed$args orderby
and order from the below code but it was displaying the rand. But i want display a post like 1 to 10 in sequence order by date. Here is an code:
<?php
// WP_Query arguments
$args = array(
'post_type'=> array( 'trivia' ),
'post_status'=> array( 'publish'),
'posts_per_page'=> '1',
'orderby'=> 'rand',
'post__not_in'=> array (get_the_ID()),
);
$query = new WP_Query( $args );
if ($query->have_posts()) {
while ( $query->have_posts()){
$query->the_post();
echo '<h2>'.get_the_title().'</h2>';
echo '<p>'.get_the_content().'</p>';
}
} else {}
wp_reset_postdata();
?>
<form>
<input type="submit"/>
</form>
</div>
<?php get_footer();?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: foreach() argument must be of type array|object, null given
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.