• hello, i have may be around 4 posts and each post contents a meta key
    example

    post1 metakey value = 8
    post2 metakey value = 4
    post3 metakey value = 5
    post4 metakey value = 4
    i want to count out the numbers and print the eq out !
    8+4+5+4 = ****

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Establish a variable to contain a running total $eq = 0; and another to contain the output string $out = "";

    Loop through the posts, such as a standard WP “Loop”. Within the loop, add the amount of the current value into the running total and concatenate the string values into the output. PHP should handle the type casting automatically, but you could use (int) to force the meta value to an integer type, as WP stores it as a string.

    After the loop runs, do some final clean up and echo the results.

Viewing 1 replies (of 1 total)
  • The topic ‘Count a numbers in post meta’ is closed to new replies.