You are overwriting $post_ids
variable on every while
loop, never collecting them.
That can be solved using
$post_ids = array();
while (have_posts()) : the_post();
$post_ids[] = get_the_ID();
endwhile;
var_dump($post_ids); // this is an array of ids
However there is simpler way, you can skip the whle cycle and simply run:
if( function_exists( 'wpseo_local_show_map' ) && have_posts() ) {
// this is an array of ids
$post_ids = wp_list_pluck( $GLOBALS['wp_query']->posts, 'ID' );
$params = array(
'id' => $post_ids,
'echo' => true,
'width' => 425,
'height' => 350,
'zoom' => 10,
'show_route' => true
);
wpseo_local_show_map( $params );
}
Related Posts:
- Get posts by list of post IDs ordered by those IDs?
- Issue with WP_Query (need a array of selected ID’s)
- Too slow when using both ‘tax_query’ and ‘meta_query’ both in WP_Query
- What kind of object type is WP_Query?
- How can I save an array from a random post sequence for later use?
- Getting an array out of WPQuery
- Get All IDs Of A Post Type Using WP_Query
- assign 2 $args to one wp_query
- Use Transient API to cache queries for all posts in all categories?
- How to get any tag ID
- WP Meta Query for some meta (array) values
- meta_query with array as value
- Placing a div or img in between a post array using WP Query [closed]
- Show one post per author and limit query to 8 posts
- How to get user_id from wordpress database inside ajax function?
- How add a custom posttype name using ACF field to a query post array
- How can I pick a single post from the latest 3?
- WP Query for variable taxonomies
- Minimize database queries to user tables?
- (Solved) WP_Query ($ args) -> How to sort letters and numbers within the same array
- Adding an array from a query string to a WP meta_query
- Weird orderby => post__in issue
- How to list custom fields as headers and list all pages sharing that custom field under it?
- Query all posts if multiple meta key don’t exist
- Removing duplicate values between two wordpress queries
- Include current post into loop
- how would i change post->ID to work correctly when querying pages?
- Combine results of multiple WP_Query to resemble single WP_Query
- How do I turn these values from MYSQL into an array
- Does meta_value (array) work with ‘orderby’?
- search serialised meta_value for date value?
- Combine 2 arrays in a query parameter
- get term id from term name
- How can I comment comma-separated array values?
- How do I add a relation parameter to my filter query?
- construct complex queries with WP User Query
- Get a list of ACF Repeater-Fields as array
- WP_Query with page_ids in arguments without a result
- Related Posts Excluding Certain Categories
- Query using string from custom field as array value
- Multiple meta query from array
- Category based on post id
- How to get specific string in explode array?
- How to avoid filling up an array each time I run a WP_query?
- Compare “Main” post ID to ID inside wp_query loop
- Remove from array in WP_Query loop
- Determine if ID is page or post and query the ID
- meta_query returning excluded result
- Display posts from an array of ID’s
- Combine relationship posts with existing wp_query
- Only show tag with the same id as the post
- Counting instances of words in the results of a post query
- sanitize_post() is not sanitizing Post Object
- Retrieve all custom field values of a specific custom field metakey as an array, inside WP_Query
- WP Query by 4 different taxonomies
- Trouble with serialized metadata
- What code to use in an array to call the current sub-category?
- WP_User_Query Orderby Not Working
- Loop through array of pages
- Repeat array inside array through while loop
- Sorting Posts by Taxonomy thats not within the query’s $args
- Related Post by Tags Code
- date_query problem
- WP_Query: Meta_Query with serialized value (or a workaround)
- how to query for meta_value have array
- wp_query – Modify $query to include duplicate content
- Iterate through ID’s in loop
- How to get several fields from wp_query?
- How to sort a WP_Query array by post_name after an array_merge();
- WordPress WP_Query Array Custom search via taxonomies
- WP Query posts__in not working with array
- Sort Posts with custom meta key by default which is currently set as optional
- Dynamically name array in WordPress loop – add/get values
- Dynamically create array from page title
- WordPress Query Returning Every Post
- Creating Custom Query
- How do I have multiple metaqueries inside one wordpress query
- I want to place a post before all others from an ACF boleen field
- after refresh the id that shows correct in first time click, changes to 1
- wp_query, calculate with two dates when ‘key’ is text format
- Orderby meta _value that is saved as an array
- Query for posts belonging to multiple categories
- Category Archive not working for pages
- View related categories in order of posts
- Rewind posts then show only first post
- modifying the loop multiple times with arguments passed through ajax to wp_query
- query only returning posts with already set custom field
- counting post from a wp-query using sticky_post
- WP_Query – show posts where meta value and user_email match
- WP_Query causing links to not work
- Using the same WP_Query for shop and widgets in WooCommerce shop
- Order posts by more than one variable (meta_key and publish date AND time)
- How can I get all the posts that are related with a specific taxonomy term?
- Show full category tree for a year with all post titles?
- Trying to use “Medium” featured image for custom post type on home page
- Combine WP_Query with array of custom data to single loop without breaking the pagination
- Create custom order sortby based on array of id
- Fetch only categorized posts
- Duplicate a Query Built with PHP and Mysql but now in WordPress
- Woocommerce orderby rand with tax_query not random