Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Be The Loop: WordCamp Chicago 2017

Be The Loop: WordCamp Chicago 2017

We live inside the boundaries of The Loop. As an intrinsic part of WordPress, does it mystify you? Are you feeling a bit stuck in there? Want to expand its limits? In this talk, we’ll go over what the loop is all about as well as learn more about the creative possibilities of customizing what data you’re retrieving through the use of WP_Query to write your very own queries and loops.

Allison Tarr

April 29, 2017

More Decks by Allison Tarr

Other Decks in Technology


  1. H’allo there… I’m Allison. ◎ Feminist. Writer. Lover of guacamole.

    ◎ Front-end developer at WebDevStudios ◎ @allisonplus
  2. We’re going to go over... ◎ What is The Loop?

    ◎ The power of customizing WP_Query(); ◎ Examples of customizations
  3. “ The loop is PHP code used by WordPress to

    display posts. https://codex.wordpress.org/The_Loop
  4. What does it do? ◎ It’s the thing that goes

    and gets your content from the database. ◎ Loops over posts to bring in data. ◎ Makes our lives easier!
  5. The Loop is Lovely because it... ◎ Saves time ◎

    Keeps your code condensed & tidy ◎ Efficient!
  6. The Loop in real talk. If there are any posts

    And only while there are still posts, Give me the post! (if not, do something else)
  7. What can the Loop output? ◎ Template Tags ◎ HTML

    your content is wrapped in ◎ Customizations (if any)
  8. Every Loop has a query. The query is the request

    for the information your Loop will have access to.
  9. There’s a few different ways to go about this •

    WP_Query() • pre_get_posts() • query_posts()
  10. Custom Post Types For use within plugins &/or widgets Posts

    by multiple authors Why would we need a custom query?
  11. WP_Query Ingredients ◎ Define what you’re asking for ◎ Arguments

    for the query ◎ The Loop ◎ Leave no trace.
  12. Arguments Your arguments feed the query. The query feeds The

    Loop. https://codex.wordpress.org/Class_Reference/WP_Query#Parameters
  13. wp_reset_postdata(); Resets the global $post data we’ve been messing with

    after a custom query. https://codex.wordpress.org/wp_reset_postdata
  14. Display a sticky post I can do anything?! Grabbing a

    random selection from a Custom Post Type
  15. Thanks! Any questions? Come hang out with me online at:

    ◎ @allisonplus ◎ [email protected] ◎ allisontarr.com Presentation template by SlidesCarnival