.= does string concatention, eg, 'hello ' . 'world' gets you hello world.
To add, use + instead of .:
// Set a default for $numbers.
$numbers = 0;
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$post_id = get_the_ID();
$party_size = get_field('reservation_party_size', $post_id);
$numbers += intval( $party_size );
}
}
return $numbers;
I use intval() to make sure that $party_size is an integer.
More reading: PHP Assignment Operators
Related Posts:
- Can an array be used as a meta_query value?
- Looking for most performant way to execute several similar WP queries within shortcodes
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Form search query – displaying ACF “Post Object” field as results
- Remove Post if Advanced Custom Field is checked to fix paging
- Nested Queries of decreasing specificity
- Use WPQuery to match to specific repeater row in post
- Query on a repeater date (acf)
- List all ACF field values across every post on one page
- Ordering / grouping posts by datepicker ACF
- Include WP_Query in my own PHP file?
- AJAX / Read More: multiple check_ajax_referer() and wp_create_nonce() not working independentely
- Display certain amount of posts on taxonomy archive page
- Conditional statement for parent, child and grandchild pages
- Result of Custom WP_Query appears on 404 Page (but result are found!)
- Show only one post for each author ( Page loads too slow )
- what is diference wp_get_attachment_url / wp_get_attachment_src / get_post_thumbnail_id?
- Modern Tribe Calendar wp-query with meta query not working at all
- WordPress WP_Query() Not working properly
- Get category name from custom loop and echo it once
- Hide post if matches current month and year
- Use WP_Query in shortcode
- Why is variable not working on custom sql query using wpdb?
- Random order of WP_Query results with highest meta value
- ACF page while loop breaks footer while loop
- Dynamic content based on a URL parameter
- Output ACF repeater on frontend user’s profile page (created with Ultimate Member) [closed]
- Security for data obtained from the database
- How to get all author posts outside of author templates
- How to get post ID in a Page?
- How to retrieve the data from the sever and displaying it in a page?
- How to overwrite orderby with add_query_var
- get_the_ID() in the footer returns wrong value
- ACF put a comma after the last repeater field value [closed]
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- How to override url params with rewrite rules vars?
- How to display SQL query that ran in WC_Order_Query?
- Store metakey value as an array
- Post not populating for custom post type based on category selection
- WP_Query multiple post results
- Infinite Loop – WP_Query
- echo var into wp_query
- Including Custom fields within the_content
- Toolbar Hidden in a Virtual Page
- WordPress SQL JOIN query
- WP_Query and help with the loop for magazine front page
- Update user repeater meta (ACF) with another user meta field value
- Wp Query : Order by distance lat,lon
- 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?
- get different meta-data of a complicated query at the same time
- Get main parent category for post (WordPress/Advanced Custom Fields)
- Using a new WP_Query inside the loop
- wp_Query with mutuplea values returns all posts
- WordPress sorting posts by date and title using a dropdown
- How to get specific multiple pages excerpts at homepage?
- ACF Taxonomy field values not select in backend
- WP_QUERY post_in problem
- how to get data from two different table from wordpress database
- Assign meta_query value to php variable
- ACF – Can’t get custom post type by taxonomy
- Advance custom fields variable with if statement & Function
- ElseIf Statement with ACF Group field
- Place product field value as variable in php
- ACF – Get ID of relationship field in flexible content
- WordPress search query, how to modify the sql
- Modify post image in full size
- Wp-query output correct, but the loop shows one less item (only sometimes)
- Get list of posts from attachment
- How to output values from a loop into a javascript array
- Pulling Products from an API
- How to display sticky post always at the top (before regular post) in wordpress?
- Scheduling a post using publish date from a custom field. Resulting post is set as published in the future instead of scheduled
- Making list of posts with chosen description
- Include search tags and users in my search results system
- Add custom taxonomy to custom search for posts
- My query keeps looping infinitely ! how to stop it?
- How to add thumbnails from recent posts to owl-carousel in wordpress automatically?
- direct query to post_meta table
- ACF Images If/else
- Only Get A Certain Number of Posts From WP_Query
- Querying posts based off a jquery datepicker
- Page returning ID from array, how to return the correct values for post in acf wordpress
- Use custom get results query to show posts WordPress
- List sibling pages widget, exclude current page
- the_post_thumbnail unless video id is added
- WP Query conflict on tag.php and category.php template
- Does wp_query and query_posts affect website performance? [duplicate]
- WordPress post pagination on custom template not working
- Add comma between variables [closed]
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- WP query with variables gives no result for specific user
- Display all categories (with link) of custom post type – WordPress
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- wp_logout action hook is not firing
- Cannot Access ACF Field Values via my Plugin
- Developing a “fallback” for empty wp_query results based on post dates