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)
- Removing any and all inline styles from the_content()
- Adding additional data to WP_Post object
- WP_Query: Why is sticky post not first item in loop?
- Displaying the category name of a custom post type
- How do I reorder (pop and push) items from WP_Query?
- How to exclude latest x posts from a paginated query?
- Most viewed post for the last 2 days using WP_Query
- Adding Post Counts to Menu (Nav) Programmatically?
- This AJAX Code Doesn’t Work – Looking for elegant solution
- Filter posts by author and category simultaneously
- How to add posts to wp_query result?
- Posts for next month
- Replace Main Query With Custom Query
- Hide Post comments when displayed via WP_Query
- Group posts by year in loop
- wp query with dynamic taxonomies and terms?
- Blogroll – Different layout for first post
- WP_Query: offset ignored when posts_per_page is -1?
- How do I use `posts_distinct` correctly?
- Automatic value for custom fields for posts
- Loop through all product posts?
- Get random posts between specific dates / of specific age
- How to find what index page a post is on?
- How to add Tags Filter in wordpress admin dashboard
- Admin Posts Table Column Fitlering is not working for Custom Post Type
- Get Posts that are in the current month or later
- WP Query to Get Array of Slugs
- How can I sort posts by the date and a custom meta field?
- Hiding Draft Post In Admin
- What is the filter or hook to add admin controls to posts on the front end?
- How to verify wp user password by sql query in wp? [closed]
- Ajax post filters not working
- Display Meta Values in Custom Filter – Admin Custom Posts
- How to return another post than requested
- Update post_content everytime a custom post is opened in backend
- Lost draft under all posts and drafts
- Get user categories with most posts in it
- Random ajax load only works with posts_per_page set to -1
- Query Posts With Over 1000 Views
- List authors with the last post title and order by last post date
- How to order posts by meta_value and title
- How to get Tags with specific post id
- Trying to alter the post_content through the_post
- WordPress query_posts by tag doesn’t work anymore(?)
- Get post content with all filters applied, knowing post id
- Ignore latest two posts
- Print out last 3 blogposts
- Filtering posts on Post Administration Page by Week Number instead of by Month
- How to group only VISIBLE posts? [closed]
- Shortcode with ‘year’ parameter
- Change the default blog post post attribute template name from “default template” to something else
- On what hook can I get the queried object’s final state?
- Is it possible to add a shortcode below post title?
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- how to handle the loop using filling bootstrap grid structure?
- Get all custom posts with a certain taxonomy
- Link to date_query results in WordPress
- When WP_Query only returns 1 post, how do I automatically redirect to that post?
- Limiting post list by taxonomy
- How to display WP Query filters?
- Finding a post’s slug
- wp_list_categories() Exclude All Categories Except One
- Function is printing twice – any suggestions?
- How to add a custom class attribute into code wrapper? [duplicate]
- Filtering private Posts
- How to add a block to a category page?
- How to use two query result together in one loop
- show loop id post , only first id can read
- Add id attribute to h1 element of wordpress post
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- filter posts based on menu_order
- Change archive results based on GET request
- Wp_query loop is not working as it should
- Show all posts from the tags without having to set all of them
- Is there a global page/post/product/anything ID?
- wp query custom orderby not custom field
- WP Query between posts custom fields [duplicate]
- Retrieve latest post by multiple categories with ID
- Update Post with Modified Data
- How to Include a common category in a custom Category Search
- wp_query select if have comments
- custom sort posts in archive/taxanomy page
- how to print loops for odd in 1st column and even in 2nd column in wordpress [closed]
- Trying to create shortcode listing custom posts, but formating not being included
- Show Title/Date/Excerpt of first post & only Title for rest in Query [duplicate]
- Get posts after calculating meta key
- Next and Previous buttons are not showing on home page for post
- How do I get content of custom post type through post ID