You’re clobbering the value in the $users
array with every iteration of the foreach
loop. To add a new item to an array, you should use $users[] = {...}
, not $users = {...}
.
function get_preselect_values()
{
$volunteers = get_post_meta($_POST['element_id'], "volunteers", false);
$users = array();
foreach ($volunteers as $volunteer) {
foreach ($volunteer as $volun) {
$users[] = $volun['ID'];
}
}
echo json_encode($users);
die;
}
add_action('wp_ajax_get_preselect_values', 'get_preselect_values');
add_action('wp_ajax_nopriv_get_preselect_values', 'get_preselect_values');
Related Posts:
- How do I get posts by multiple post ID’s?
- What does setup_postdata ($post ) do?
- Query for custom post type? [closed]
- get_posts – get all posts by author id
- Why get_posts are only showing five posts (retrieved by assigning a category to them?
- Exclude Current Post from Recent Posts Loop
- get_post random and order by not working
- Alternative to get_posts() due to multithreading cache crash
- How to get current post ID in quick edit callback
- get_posts with meta_compare=’LIKE’ not working
- How to restore deleted pages/posts?
- Get the exact SQL query that get_posts() generated
- How do you get posts by meta_query using the JSON API plugin?
- Why favour the standard WP loop over iterating over (new WP_Query())->get_posts()?
- get_posts inside cron
- get_posts not honoring post_status
- get_posts returning empty array
- Problem with get_posts, tax_query and counting the number of posts
- get_posts cannot grab from specific category
- Check If posts exist in custom post type category, outside of loop
- data returned from get_post($postId) have different keys than wp-json/wp/v2/posts/{postId}
- How to limit get_posts()?
- What’s the difference between “get_posts” and “wp_get_recent_posts” when used with “setup_postdata”?
- Serialized array, grab specific posts with meta_key/meta_value[0]->is_featured
- How do I combine these 2 queries
- get_posts gives different result than wpdb->get_results
- Trouble using get_post
- Cache Get_posts
- Get latest posts from multiple categories
- Get_Posts, only if in both categories
- Posts not showing in correct Alphabetical or ID order when using get_posts / orderby but only on production server
- Secondary Query Is Breaking Main Query
- var_dump and print_r cause white screen
- `get_posts()` ignore my custom post
- I don’t arrive to do order_by title when i have a conditionnal year in a request
- How can I display a single post link, based on title sample and change monthly?
- get_posts() doesn’t consider user permissions
- Meta query: get posts with value in a multidimensional array
- Better way to list links with different meta values using same meta key?
- How to update all posts but the current one (post__not_in not working?)
- How to get the post content from a category on my homepage
- get_posts() not working in functions.php
- Query Problem in getting top viewed posts
- get_posts not working as expected
- Get all pages and posts with get_pages() or get_posts()
- Display post details by post ID
- What is the p parameter in a get_posts() parameter array?
- Inserting post content into pages when using custom taxonomies
- Unique Problem with the php date and get_posts
- get the post_date of ID
- Get posts by language in Polylang plugin
- Query get_posts by level depth
- Auto-change Post Status on First Page Load
- How to use WordPress Conditional Tags in get_posts foreach loop
- Hide gravity forms
- Not able to get random post
- get_posts returns all posts
- SQL query generated by WP_Query is not the same what request echoes
- Calling setup_postdata() causes “Call to undefined function get_userdata()” error?
- WordPress Random post (last 3 days posts)
- Cron task firing but function not working
- wp json api – get posts by category
- Custom Post type Query post is not working
- Get all posts with a certain meta key, except for one with specific title
- Can’t get Category link inside get_posts
- List all pages including archive
- Yet another get_posts() in explicitly defined order problem
- Modified home page query does not yield expected results
- List random posts on single page in the current category
- Add ul to its children with get_posts
- get_posts by id not working
- Select objects from get_posts()
- Single random post in homepage
- Get posts in archive page
- Paging result of get_posts in function
- get_posts returning empty array
- Update all WordPress posts’s title and content then display them in a table
- get_post Question
- get the_content by ID and save the result to one array
- get_posts – check if custom field has content?
- Zero posts returned with get_posts() on edit.php, but posts are returned on post.php
- Why does ‘meta_key’ return an empty array in get_pages
- Better way to query posts?
- Using get_posts, I need to use a combination of OR & AND relations
- Get number of posts in each category since last visit
- Get_posts not returning any posts when used with switch_to_blog
- How to Retrieve Post ID of another page
- Get images by category
- How To Use get_posts & get_the_post_thumbnail Outside The Loop
- WordPress – List Sub Categories and Sub-Sub Categories, With Posts
- How to show only 1 post from a specific category on the front-page
- Query for draft or scheduled post
- get_posts() and ‘posts_per_page’ arg
- get_pages not returning any results or error when get_posts works
- Show posts in a list separated by day
- Function to get content by ID
- Display post’s description and caption
- get posts based on category and post meta
- How to show only text from post in WordPress
- Install wordpress and replace database (from previous site)