Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Wordpressing Displaying only Posts from 2014

Options
  • 12-01-2014 9:53am
    #1
    Registered Users Posts: 437 ✭✭


    Hi there,

    Another Wordpress question. Although the theme I'm using seems to use standard loop code, it will only display posts made this year, while the blog I'm working on has many posts made in 2013 and before. The loop code is as follows:
    $args = array('post_type' => 'post', 'posts_per_page' =>  '10');
    					$loop = new WP_Query($args);
    					while ($loop->have_posts()) : $loop->the_post(); ?>
    

    Under "Settings -> Reading" the posts-per-page value is also set to 10. If I manually alter the publication dates of the posts to 2014, they display perfectly.

    Can anybody shed some light on the issue?

    Cheers!


Comments

  • Registered Users Posts: 97 ✭✭myIdea


    I think you could just add to args array :

    [PHP]
    'after' => 'January 1st, 2014',
    [/PHP]
    or try Before:

    [PHP]
    'before' => 'January 1st, 2015',
    [/PHP]

    Like so...

    [PHP]
    $args = array('post_type' => 'post', 'after' => 'January 1st, 2014', 'posts_per_page' => '10');
    [/PHP]


  • Registered Users Posts: 6,494 ✭✭✭daymobrew


    t1mm wrote: »
    [php]$args = array('post_type' => 'post', 'posts_per_page' => '10');
    $loop = new WP_Query($args);
    while ($loop->have_posts()) : $loop->the_post(); ?>[/php]
    It is strange that 'posts_per_page' is being set in the code.

    There must be somewhere else that is setting it display from this year - it could be in functions.php or under the mu-plugins directory.
    Search for 'year' or WP_Query.

    BTW, what is the name of the file that the above loop is from?


  • Registered Users Posts: 437 ✭✭t1mm


    Thanks for your replies guys. I think the configuration I'm looking for is buried somewhere in the theme which I cannot edit through Appearance -> Editor. I've asked the site owner to send me a copy of the theme so I can check it out. Previously tried the "after" attribute to no avail.

    posts_per_page wasn't actually being set in the code - it was pulling it from somewhere else, but I just hardcoded it to prevent confusion here.

    It's a 1page template, and the file is called index.php.

    Thanks again for your help, I'll report back once I get my hands on the theme files :)


Advertisement