If you would want to pass the whole wp query you could pack it up in arrays, then json encode it and just write it out in a tag.
<?php my_posts = array();
while ( have_posts() ) : the_post(); ?>
<?php
$properties = array(
'title' => get_the_title(),
'link' => get_the_permalink()
);
$my_posts[] = $properties; ?>
<?php endwhile; wp_reset_query(); ?>
<script>
var posts = <?php echo json_encode($my_posts); ?>;
console.log(posts);
</script>
Of course this might not be the best idea securitywise.
Related Posts:
- Using a custom WP_Query with get_template_part loop
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- How to make WP_Query ‘post__in’ accept an array?
- WP_QUERY Get posts by category and similar name (Like)
- Using get_posts vs. WP_Query
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- Is it possible to wrap Geo Location search around WP_Query?
- Merging multiple wp_query objects
- Query causing load because of SQL_CALC_FOUND_ROWS post counting?
- Using custom meta_query with relation not working as expected
- Nested query inside Logical operator OR not working in meta_query
- SQL Statement generated by WP_Query not producing expected results
- Only show first post to match certain criteria within WP_Query
- What is an efficient way to query based on post_meta?
- Pagination wont work with search results template [duplicate]
- Pagination Not working on Home Page with 2 Query
- WP_Query in a shortcode
- Get all posts without tags
- Sort by meta key on archive page
- Get post ID’s from one query and exclude from another
- What are the differences between “Latest Posts” and “Static Page”?
- Retrieve or Query Pages by ID
- WordPress Query is taking more then 20 second and stuck on creating index
- Modifying raw $_POST data early in the lifecycle
- Searching through different categories on different pages code is not working
- Get the Plugin Which Triggered a MySql Query in WordPress?
- Difficulty with rewrite rules
- how to get the id for a post from within a post and return post meta for it
- Show selected images on top in Media Manager
- How to make this WP_Query run faster on a WordPress website?
- How do I sort posts with multiple pages
- Complex date range with WP_Query and BETWEEN
- Attachment changing page’s permalink – $post not resetting?
- showing all search result in one template
- List custom taxonomy terms sharing posts with a term from a second custom taxonomy
- Make (post) query a clickable link
- How to set pagination to work with ‘/page/’?
- How can I filter by slug depending on language selection
- How to duplicate 5 posts out of WP_Query results?
- Ajax WP_Query reutrns no results on author.php
- Large AND OR query timing out
- WP_query wp_posts_counts returns only count of admin and not users
- Categorising search results based on Custom Fields
- get_post_meta slowing down my page load (in a plugin)
- How to query for all posts that have a particular meta key?
- Custom taxonomy.php not working
- “tax_query” parameter is ignored when “p” parameter is set in WP_Query
- Ajax future single post query doesn’t work when NOT logged in
- Conditional sorting with variable using WP Query
- How can i share WP_Query between multiple functions?
- Advanced WP_Query with meta_query, orderby?
- sort and display posts by custom field (wp-query and the loop))
- I need help using pre_get_comments to limit comments in the comments admin screen
- WP_Query Taxonomy categories filtering
- WP_query only displays one of my custom post type entries
- Assign a minimum result count for WooCommerce query shortcodes?
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- How to create dynamic value in WP_Query meta_query
- Retrieve data from wordpress db via input and put those result in dropdown
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- query post by author gender
- How to access $wp_query object from array of posts given by get_posts?
- Display all attached image of every post of custom post type and link to original post
- Links in the_content not linked
- how do I write this wp_query select statement?
- Post incorrectly excluded when using “category__in”?
- How to search by slug and old slug in single API
- Reciving Error 404 blog/page/2/
- query hook parse_tax_query function takes no effect
- Categories In English version showing not canonical URL, instead shows query search result
- Multiple meta_query not returning rows
- Related posts queries
- Check for not NULL not working in meta query
- What code to use in an array to call the current sub-category?
- Pagination for Category does not work
- Query against multiple locations within single custom post type post
- Order by meta date with a thousanth of a second defaults to post order
- How to debug none working search query?
- Order by Date Custom Field
- WP_Query showing all posts, except from category X, unless it’s also in Y
- ACF query-pass field value
- How to make a search query if not found in post table then search in postmeta table?
- Show posts by category – category ID not working
- Search Field that allows options of “Match any keyword” or “Match all keywords”
- WP_Query for posts that have postmeta assigned to a taxonomy
- Paginated Author.php not using Author.php template
- Help displaying related categories
- Show more than one post on the main page excluding certain category
- How to make a wordpress loop file that displays posts based on certain conditions
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- wp_query – show pages that have parent defined
- How do I display posts with specific value in a custom field into my loop?
- Orderby Meta Value and Query from Meta Query
- WP Query to order posts by multiple meta fields
- Order by multiple meta keys on wordpress
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- paginate_links() with Custom Taxonomy
- Parsing External Table Arguments
- Output ACF field dynamicaly within a taxonomy loop [closed]
- Why am I getting no results of a query placed after another query?