You will either need to globalize $books
(if you want to stick to get_template_part()
) or use
require( locate_template( 'loop-books.php' ) );
instead of get_template_part( 'loop', 'books' );
. This issue is caused by $books
in loop-books.php
being defined only in the scope of get_template_part()
.
Related Posts:
- get_template_part causes 500 error
- Check for the main query from the template
- Custom wp_query inside a conditional stament inside a template part doesn’t work: why?
- Continue loop after $queryObject
- Print post data inside loop using theme content template
- First post outside of loop, homepage only?
- Can I force WP_Query to return no results?
- Multiple WP_Query loops with Pagination
- WP_Query vs get_posts
- Pagination returns 404 after page 20
- Make loop display posts by alphabetical order
- get custom post type by tag
- Order posts by ID in the given order
- How-to exclude terms from the main query the most performant way?
- Pagination with WP_Query is buggy – working for some pages, but not the others
- Get the number of posts from the current page results
- How to place a loop within another loop?
- Group posts by custom field
- Pagination/infinite scroll with WP_Query and multiple loops
- Ajax Infinite Scroll In Custom WP_Query Loop Not Working
- How to change a custom query into a standard loop?
- get_posts() seemingly ignoring post_type
- Injecting content with $wp_query->current_post restarts from zero on paged pages. How to inject content after X posts, regardless of pagination?
- Woocommerce custom loop to show all the products [closed]
- How to show the posts of some category first, and then all other
- wordpress query in header won’t reset and corrupts other loops
- Pagination stops at page 6
- Paginated HTML Sitemap
- How to limit total number of posts in wp query loop?
- 2 loops on page – one with orderby rand second orderby date
- Undefined WP_Query::has_posts()?
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- Pagination is broken and I need help fixing it
- How to use WP_Query to display many posts?
- Counter problem, infinite loop when post_per_page equals X
- How to vary post loop results layout and resume?
- Five posts from a category in footer
- Get a post from other loop each n-posts in the main loop
- Loop returning only 1 result
- How to get all unique categories for posts in loop?
- Using the_post_thumbnail resets current loop item ID
- Order by empty custom field
- Some doubts about how the main query and the custom query works in this custom theme?
- Post loop for all taxonomy terms
- Stuck in the query loop
- New WP_Query loop in admin causes problems
- Only display post if published in last 24 hours?
- Need to convert string of term ids into comma separated integers for use in an arguments array
- WP_Query loop else statement not executing
- How do I get my custom query to work with search results after the first page?
- Issue with front page navigation after upgrading to 3.4
- Include current post into loop
- How to display the featured image for each post?
- Exclude recently updated post from custom WP_Query using multiple loops
- get_posts output always same post
- How to use WP_Query() on single.php?
- difference between querying database and using the loop
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Loop increase in while loop not working
- posts archive page – closing WP_Query loop correctly [closed]
- has_excerpt() not working inside wp_query
- AJAX Breaking Offset Argument In WP Query
- Continue or break the while loop
- Loop posts based on permalink term
- Save (and exclude) posts from loop to use in another loop on page
- Get all posts with empty meta_value
- Loop 3 posts column wise and continue the loop into same columns
- Does putting queries within loops cause an issue on WordPress?
- Query Taxonomy By Page Title
- Function using get_posts() with tax_query not working when called from functions.php
- How to change the default post type over the loop?
- Paginate pages with dynamic query
- WP_Query loop doen’t work with my custom taxonomy
- Determine if ID is page or post and query the ID
- How to make the ‘request’ filter work?
- get_children() Archive Template
- How do I stop the same post showing multiple times in a archive?
- Bootstrap grid while loop
- how to get custom attachment url?
- How can I use WP_Query to sort ‘event’ custom post type by date?
- Display posts side by side with custom query
- WP_Query & Duplicate entries
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- Calling a function with WP_Query only ever brings the first result
- query_posts() doesn’t seem to be called in my page
- Some doubts about how the main query and the custom query works in this custom theme?
- Ordering Posts by parent category, name ascending
- Set Transient on CPT
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Load 3 posts in flexslider slide [closed]
- Issue with WP_Query (need a array of selected ID’s)
- Multiple wp_query loops showing first 5 posts on all pages instead of older posts[Resolved]
- Next / previous posts link doesn’t show up with Posts 2 Posts
- How to exclude posts ordered by comment_count from subsequent wordpress loops using WP_Query?
- $query conflicting with other queries in the same page
- WordPress Post Looping? [duplicate]
- Carousel Loop only duplicating
- How to show featured post first, then separate loop for other posts
- Pagination only showed when no category is set in wp_query