It looks like you’re calling preparePDF( $wp_query )
inside your callback, but $wp_query
isn’t defined and the global $wp_query
shouldn’t be accessible there without global $wp_query
.
Try instead preparePDF( $query )
and use wp_reset_postsdata()
to restore the global $post
object.
Another important thing is that you must run your preparePDF()
function after WP_Query
has fetched the posts from the database. So don’t use the pre_get_posts
hook, use a later hook instead. But that hook depends on what you want to do with the posts. I also don’t understand what you’re preparing with your preparePDF()
function.
Remember to use WP_DEBUG
on your dev install, to catch any PHP errors, warnings and notices. Check for example the Debugging in WordPress in the Codex.
Related Posts:
- If specific user role then sticky post
- How can I remove posts of a certain category from homepage after a specified time period?
- Change post order random through out the entire WordPress
- How to filter my search in post if contains a word in title, content or excerpt?
- How do I display main query posts in random order using add_filter
- the wp_post_update isn’t working all the time
- Display/Filter post using if else statement
- long-title posts do not want published
- Override wp_link_pages pagebreak with filter
- wp_query posts sorting doesn’t work
- Add custom PHP (no-SQL) filter to WP_query
- Filters do not work when there are multiple (one works)
- Posts and Attachments with “Published” status in Search
- Random ajax load only works with posts_per_page set to -1
- How to : pagination in 3 different custom loops on the same page
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- Exclude the first ‘n’ number of posts of a tag from home page?
- Query posts and return XML
- how to change the number of posts returned in a specific loop without making it global?
- Query Posts With Over 1000 Views
- How to allow visitors to filter posts by multiple taxonomies
- posts_per_page option limits the number of Gallery items
- List authors with the last post title and order by last post date
- How to order posts by meta_value and title
- wp_query random post
- wp_posts table: safely remove unused columns to save database storage
- Query Posts by Custom Field
- Adding a blog archive with pagination using WP_Query
- How to get Tags with specific post id
- Redirect to another page using contact form 7? [closed]
- how can i change WP main archives loop to sort by name or title
- Trying to alter the post_content through the_post
- Using wp_list_pages() after calling query_posts()
- how to get post order by post id wp_query?
- Possible to alternate between two loops
- Nested WP_Query breaking loop
- WordPress query_posts by tag doesn’t work anymore(?)
- add to end of post in the loop with plugin
- Add filter to the end of the post
- How to display all posts divided/ordered by post date? [closed]
- Why Query is returning empty array?
- How do I extract just the post ID of the first item in whatever WP_Query returns?
- Show post content and title in diferent divs using WP_Query using a loop
- Get post content with all filters applied, knowing post id
- Why are my paginated posts always returning the same results?
- Ignore latest two posts
- Is it possible to use WP_Query to only pull posts with attachments?
- Adding bootstrap classes to video shortcodes
- Is it possible to filter the main loop to exclude posts from a specific category?
- Show posts by author of membership level (Paid Membership Pro)
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- meta_value timestamp older than now
- Every second post different class in blog view
- Loop doesn’t exclude the specified category in home page
- Get posts with multiple categories
- Do not show children of a category
- query post limits
- Display posts of specific category term
- Print out last 3 blogposts
- why the same code got different results when using query_posts in functions.php and index.php
- Query posts by Author and/or by Tag
- Query for first 3 posts to change the look and feel
- How to get posts published on the latest date?
- Why posts array is empty?
- Can’t understand why sometimes a [caption] field appears
- Page and post loop same template
- Modify posts listing at back end
- Filtering posts on Post Administration Page by Week Number instead of by Month
- Prevent posts with certain post_meta to be edited
- Getting blog pagination to work on page set as front page
- How to group only VISIBLE posts? [closed]
- How to check in functions.php if there is data in a WP_Query?
- Shortcode with ‘year’ parameter
- search blog posts by author first name and or last name
- Show metabox value last post excerpt, title and link
- Change the default blog post post attribute template name from “default template” to something else
- Hook for changing excerpt content when excerpt not set
- On what hook can I get the queried object’s final state?
- Is it possible to add a shortcode below post title?
- unique post in “$args” of wp_query display more than one post
- Display current post position in Elementor Posts widget
- Post filtering is returning blank page
- Why in my query is display two title?
- Migrate posts from category and sub-category via SQL
- How do I insert a after every 5 posts in a WordPress Loop that infinitely loads posts?
- wp_query with ajax
- How to give classname to post if post has no content?
- Custom wp-query in wordpress rest api
- WP_Query: Show 10 posts in date order, first three random
- How can I insert a new markup element after 4 posts automatically? [closed]
- Exclude some posts from displaying in wp_query based on some condition
- posts_per_page returning only one post
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- If no posts exist for current day and month, show the next available day of posts
- How include css class based on post ( in loop ) slug?
- WordPress Loop: How to display recent posts in multiple divs
- Random posts that always include a particular post?
- Need to know custom code to display random and most viewed posts in wordpress posts and pages
- Related Posts function not working
- How to retrieve certain number of images from a wordpress post?