I am facing problem of showing articles from past years till current year in wordpress.
The problem is that i have articles in two years (2014, 2015). By query wp_query
i can display all articles from 2015 and 2014 also. But in 2014 its displaying articles from june onwards means current month and march april may are missing.
This is my link http://www.za-beauty.in/lets-talk-za/
You can check it in 2014 year March April May articles don’t come on left side.
My code below
<?php
$args = array(
'post_type' => 'articles',
'tax_query' => array(
array(
'taxonomy' => 'article_categories',
'field' => 'term_id',
'terms' => array( 18, 19, 20, 21, 22, 24 ),
),
),
);
//print_r($args);
$query = new WP_Query( $args );
?>
Please help .
I want to display all articles of mine and if i add new articles in 2016 years in future it should not create problems the articles should display all.
Most probably your problem lies in
posts_per_page
. If you don’t specify theposts_per_page
parameter, your query will use the blog’s defaultposts_per_page
setting as set in the reading setting page. If this is set to say 20, your custom query will only get 20 posts per page. In most propability, this is what you are seeingYou should set
posts_per_page
explicitely in your query to get more posts. A value of-1
will get all posts matching your query.Just one note, reset your custom query and all custom queries with
wp_reset_postdata()
after you are doneHave solved this problem on my own. The problem is that we have to explicitly define date query parameter so that it shows the post from a given range. Without date query it will show the post from the current month, to override this we have to tell the query to show post from this range to that range (JAN 2014 to DEC 2015).
HERE IS THE REVISED CODE 🙂