This approach sounds complex, hacky and not reliable, as there could be various filters/actions that might be skipped.
Two alternative semi-workarounds comes to mind, to get the wp_nav_menu()
and body_class()
, for a given post page:
-
Use the HTTP API / Ajax to make a request for the post page and e.g. use a GET parameter to return only these values. This might be slow for many posts.
-
Generate these values when the post page is loaded and cache it for some time. We could e.g. store it with the post meta API or use the transients API, depending on our needs. We would have to keep in mind that the amount of traffic can vary for each post page.
Related Posts:
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- Get post ids from WP_Query?
- Nested meta_query with multiple relation keys
- Some doubts about how the main query and the custom query works in this custom theme?
- Creating attachments archive in tags and categories
- How to use ‘WP_Query’ or ‘query_posts’ to display content in a descending order
- Get next/prev image/attachment in time with date query
- parse_tax_query causing Navigation Menu To Disappear
- 2 queries with counters
- Show single posts date, in a page of posts
- Max Posts and Memory Limit
- How to get current page nearest parent id?
- How to get main menu only with wp_nav_menu
- specific post is not excluded from the loop
- Why doesn’t my WP Meta Query return any results?
- Multiple Query_Posts
- Paginate pages with dynamic query
- filter posts by meta key with pagination
- Trouble Making WP_Query paged
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Determine if ID is page or post and query the ID
- How to query for a page, get data, then query for child pages of that page
- Custom template for password protected page
- WP_Query Class custom field parameters
- Add AJAX “Load more” on custom query block
- Posts limit on homepage (genesis framework)
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- Optimising WP_Query with ACF Fields
- Elementor posts custom query based on tag [closed]
- Query post and sort by custom value calculated with custom field on cpt
- Filter products on category AND tag
- Query post ordered by meta value that show first post that contained a tag
- Facing problem with tax_query results
- How do i create a custom post query when the meta value is an array?
- query hook parse_tax_query function takes no effect
- Duplice post with standard WP loop – fixed by using query_posts() instead
- ElasticPress is (aparently) messing with my search filters
- pre_user_query vs pre_get_posts
- How do I stop the same post showing multiple times in a archive?
- Get posts that match defined arrays of tags
- Query for current post
- Custom query to retrieve oldest post and retrieve others with date interval
- Order by meta date with a thousanth of a second defaults to post order
- Custom query for custom post type not getting correct post ID
- trying to change from query_post to WP_Query
- Problem with my loops
- How to query most recent post for each author?
- Sorting query_posts() with a complex orderby filter
- I need query_posts() to order results first by a meta value and then by post ID
- Displaying Pages in Nav Sub-Menu with Specific Taxonomy Terms?
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- How to search CPTs in draft using get_page_by_title()
- How to show post title in content editor in backend?
- How do I hide submenus from the top menu bar?
- My entry results are not consistently alphabetized
- Orderby query does not work for custom fields even with meta query
- Merge two queries and remove duplicate
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Seach and categories not working when ignoring sticky posts in main loop
- posts_per_page increment additional post
- Custom WP_query and integrating into theme file
- Pull posts from all categories if quantity is not met?
- Query_post 5 post first / last of post_id
- query_posts() doesn’t seem to be called in my page
- Modify query to exclude certain ids and certain parents and its corresponding children
- Some doubts about how the main query and the custom query works in this custom theme?
- Fetching $_POST from Page Template into functions.php
- How to order by datediff in WP loop?
- how to exclude store in clipper theme wordpress code php
- Ordering Posts by parent category, name ascending
- Display post list within category list sorted by name [duplicate]
- Show parent’s child and also child’s, child on a page?
- Optimising specific Query with ACF meta objects
- How to organize a WP_Query’s list of posts by category and display category title?
- When should you use WP_Query vs query_posts() vs get_posts()?
- query_posts with sorting on a custom datestamp
- query post based on comparison
- How to query post ids liked by the Author
- Converting an existing query_posts to WP_Query
- WordPress Query showing multiple titles
- Query Posts by date range with fixed beginning and end
- custom query to get posts
- get contents and permalink from a specified page
- Multiple loop for “featured” items returns wrong posts
- Having trouble using this post category query on multiple pages?
- Query Posts to fetch Posts with Unique Tag
- Help in query for list links
- Exclude categories and subcategories in QueryLoop
- query_posts problem – need help
- WordPress pagination returns the same posts
- Incorrect posts displayed on category page
- WP Query – Show custom posts only if user contain some user meta
- Show number of posts AND number on current page (cannot make it work)
- new WP_Query with order args – no more distinction between categories
- Adding a language rule and displaying posts with a custom taxonomy term on its archive page
- Modify WordPress Search
- post per page for differents post types in a same query
- When to use WP_query(), query_posts() and pre_get_posts