Look closely at $offices:
array (size=500)
0 =>
array (size=1)
'id' => string '1382' (length=4)
1 =>
array (size=1)
'id' => string '1330' (length=4)
That is not an array of IDs. It’s an array of arrays. $offices[0] is not '1382'. It’s an array. So implode() on $offices is trying to concatenate arrays, which is what’s causing your error.
The cause of the error is how you’ve used array_map. If you want to return this meta value for each post in an array, then you should only return the value, not a new array:
$offices = array_map(
function($post) {
return get_post_meta($post->ID, '_octopus_id', true);
},
$query->posts
);
Now $offices will be an array of IDs, which can be imploded.
Related Posts:
- Inject post (from specific category) between posts in Loop
- Count number of published posts by type
- Get taxonomy terms only of the WP_Query current posts
- Hide post if matches current month and year
- How can I use wp_query to show all product data using just the products ID?
- How to store post ID’s in cookie or session to display the same posts later
- WP_Query: getting posts where custom field exists
- Store metakey value as an array
- Increment paged on WP_Query
- Modify main query before it run without pre_get_post
- Do not duplicate posts with multiple categories in multiple loops
- array_rand not working correctly?
- WP_Query() load selected post
- Wp Query : Order by distance lat,lon
- WordPress sorting posts by date and title using a dropdown
- posts_per_page displays only 2 posts instead of 4 posts
- Query on a repeater date (acf)
- Need to show 7 posts from actual date
- Check the database for a postmeta field
- Getting info about selected posts using one WP_Query
- How to display last whole post on the homepage
- Only Get A Certain Number of Posts From WP_Query
- insert thumbnail image from php script
- Weird Behaviour: Not all WordPress Posts appearing
- List of child pages fetch next results at link click
- Query category-specific, paginated posts and allow viewer to change sort order
- Why does WP_Query show only the same post even with different categories and endwhile?
- How to modify this function to exclude also the post belonging to a specific category?
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- Handling error states with admin_post
- Why does “get_option” pull in the older value in options.php, rather than the newer value, on submission of a form?
- Search widget breaks when using multiple loops?
- WP_Query use for a filter with multiple Taxonomies and Terms
- Display related products with custom output
- Get_the_author doesn’t return author name
- Accessing post->ID outside of the loop for listing child pages
- Custom page archive query by url var calling page twice on one of my custom queries?
- How to query for posts with a null or blank post_name?
- Add more button if more 8 items
- Post repeating with infinite scroll
- Redirect to another page using contact form 7? [closed]
- Fatal error: Call to a member function query() on a non-object
- Is it possible to retrieve all posts with a certain value for metadata?
- How to avoid duplicates when creating recent network posts
- Update post title from external file?
- set post limit at load more ajax wordpress
- Trouble inputting variable into WP query
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- Only show first image in foreach loop
- Post not populating for custom post type based on category selection
- Infinite Loop – WP_Query
- show recent posts php code error?
- Post to WordPress from another Server via PHP
- Wrap posts p tags in div
- WordPress SQL JOIN query
- WP_Query and help with the loop for magazine front page
- How to WP_Query posts order by parent title?
- search.php to search only the post title
- WP_Query – How to query all of post types categories
- How to work Woocommerce pagination inside shortcode?
- Generating 10 000 WordPress posts using PHP and avoiding Server Timeout error
- If Post Published Date or Modified Date is 1 Year or Older, Display Notice on Post Page
- Filter wordpress posts without searching the keywords in the post content
- wp_Query with mutuplea values returns all posts
- Use WPQuery to match to specific repeater row in post
- WP_QUERY post_in problem
- How to get post titles by post ID and integrate with my code?
- how to get data from two different table from wordpress database
- Assign meta_query value to php variable
- Infinite looping next post link within a certain category on a post
- WordPress search query, how to modify the sql
- Modify post image in full size
- How to use a PHP file to control the content of a blog post
- Custom Post By Category
- Making list of posts with chosen description
- Ordering / grouping posts by datepicker ACF
- Include search tags and users in my search results system
- Add custom taxonomy to custom search for posts
- Using Tag Groups: Displaying groups and adjacent tags of current post
- My query keeps looping infinitely ! how to stop it?
- How to add thumbnails from recent posts to owl-carousel in wordpress automatically?
- Display 6 most recent post on homepage?
- Apply filters when loading post via ajax
- Querying posts based off a jquery datepicker
- How to call post title and post summary to other part of site?
- Published custom posts missing
- Use custom get results query to show posts WordPress
- Add Custom Post Type on the Fly or create an array
- WP Query conflict on tag.php and category.php template
- WordPress article with 50 000 words loading slow – 100% cpu
- Display post of specific category on page
- WP query with variables gives no result for specific user
- Display all categories (with link) of custom post type – WordPress
- Changing regular db connection to $wpdb
- XML WP_Query problem in PHP 8.0 and 8.1
- How do I display WooCommerce products in my query to rows of 3?
- How to get ACF field to show up on all posts on front end?
- AND and OR in my CPT search query depending on checkbox
- How can I save the HTML output of a WP_Query function as a variable?
- How do I use fields => ids in an array with WP Query?