• Hi – I’ve read loads on this, some it contradicting, but want to figure out the best way to create various lists of posts on the same page for different categories in the most light-weight way (i.e. with minimum database hits).

    The site I’m working on could loosely be described as a magazine style site with lots of posts in different categories.

    On my homepage I intend there to be an image based grid of featured posts, followed by a row of ‘recent posts’ (with thumbnail and titles), followed by a list of 5 posts from one category (thumbnail, title, excepts and permalink) and then another list of posts from yet another category (with just titles and permalinks).

    Which should I use: get_posts or wp-query for each bit?

    Does it make a difference?
    Is one more efficient than the other?

    OR should I somehow be making just one big query for everything and filtering that in different ways for the different sections / lists mentioned above? Can’t see this option working though as there will pretty quickly be hundreds and hundreds of posts.

    I’d be really grateful for your input and thoughts! I’m keen to keep things as zippy as possible.

    Thanks
    Stef

Viewing 1 replies (of 1 total)
  • Thread Starter tictok

    (@tictok)

    HIya – just to chime into my own post a little;

    I watched Andrew Nacin’s Wordcamp talk on wp-query.
    https://wordpress.tv/2013/03/15/andrew-nacin-wp_query-wordpress-in-depth/

    Learnt so much! Definitely going to try using pre_get_posts on a conditional basis in functions.php

    So, I understand a lot more now, but I don’t understand why both get_posts and wp_query exist? Why not just one of them?

    Sure wp_query returns more data than get_posts (I think?), but where would it make sense to use get_posts instead of new wp_query? Is the only real difference the get_posts returns it’s results in an array and all data stays within that function?

    Thanks

Viewing 1 replies (of 1 total)
  • The topic ‘get_posts or wp_query? Most efficient option for multiple sections on 1 page?’ is closed to new replies.