.=
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
- Add css class ID to largest and smallest number a custom field in wp_query
- Best Practice for PHP
- Conditionally loading JavaScript based on the Advanced Custom Fields in the post
- retrieve thumbnail from post ID of best selling product in category
- How to create a WP_Query to search the Title or Tag?
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- how to display active, upcoming and past event with featured listing with pagination
- Get list of WP Updates Across Sites
- How to Explode a Textarea Field and Echo each line separately, wrapped with HTML
- WP_Query meta_query results date by date
- WP_Query sort using multiple numeric meta values
- Help with adding pagination to custom wp_query
- How to get to a specific position in wp_query?
- Advanced Custom Fields: Post Object – Not returning data [closed]
- API response to be stored locally
- WP_Query loop, does not display special characters in title correctly
- Remove query string specific key value
- How to filter posts by post format “standard” from wp-json api?
- Importing hard coded custom field into acf field
- Change output based on text field value
- Using foreach loop breaks
- Saving an array of dynamic repeater data as post_meta
- Loading the same WP_Query in two different wordpress .php templates
- How to prevent WP_Query function from returning all posts when empty?
- Unread Repeater field IMG alt not working
- Get users that likes the post
- Slick + PHP + ACF + JQuery slide reveal not working
- inserting a post from an extern php file but post content doesn’t show on wp site
- Advanced Custom Fields not displaying
- Exclude posts with specific metadata from search?
- How to create an ACF shortcode with Repeater Field in WordPress? [duplicate]
- How to show meta value code HTML after x paragraph
- Can I set up a hover animation in CSS depending on a PHP conditional?
- Get ACF options field in PHP acting as CSS
- Conditional multidimensional arrays and array_map
- How can I count ACF sub_field with a certain value
- change the default order of posts only for specific categories
- extract serialized array to use for wp-query
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- How to get post category list as select in front-end?
- Advanced Custom Fields [closed]
- Order a WP_Query by meta value where the value is an array
- ACF Unexpected T_CONSTANT_ENCAPSED_STRING [closed]
- Using multiple variables to assign categories to an array
- Search.php gets metadata from first post
- Let current user know pending posts counts using wp_query
- Foreach loop is unexpectedly outputting an extra empty a tag
- get_terms with specific id order
- How to store checkbox data for individual users?
- “pre_get_posts” orderby custom date field in different format?
- wp_query – Exclude the first thumbnail from lazy loading on archives
- How to call my PHP function with AJAX ? wp_query
- Usermeta data unserialize, extract and display in table in WordPress
- If Statement is Ignored?
- ACF values to Script with auto refresh
- Trying to get pagination working on WP_Query() post grid
- Advanced Custom Forms PHP formatting for do_shortcode
- Possible to edit custom date field and display?
- ACF Gallery field images donwload
- Check the database for a postmeta field
- ACF under category name in shop page [closed]
- WP_Query To Display Product Of Brand On Taxonomy Page
- ACF background-color per post in a WordPress loop
- Combine multiple queries, array_unique returns nothing
- wordpress query returning unexpected results
- Custom Post type Ajax search results
- Display only upcoming events / Show all events when archive year is selected
- Position a repeated article blocks
- ACF + WP + Slick Slider Repeater Slide Group PHP not Displaying [closed]
- wp_query beginner
- Transfer WordPress Login Session to an Extended Webpage on the Same Domain
- How can I display a query in a page?
- Add post class in custom loop (WP_QUERY)
- WooCommerce – Print Processing orders [closed]
- Why does WP_Query show only the same post even with different categories and endwhile?
- show/hide attachments
- Post Title Not showing up
- WP_Query based on another query on the page
- Order woo products, but first products must be with acf fields
- Show post like this image in my newssite [closed]
- Display biography post for today’s birthday person
- Variable ++ in query loop
- Count custom posts type and filter by tag
- AJAX WP_Query’s order and orderby parameters not working
- Add adjacent post function inside custom recent post function
- How do I exclude the current post from the upcoming post query
- Exclude first post from wp query
- How to create advanced custom fields for backend content
- Date not working correctly
- External WP_Query call from PHP crashed after version update