PHP’s count() function is generally used to count elements in an array, but you’re counting the value of a string, and that always returns 1. You can just add 1 in your if statement.
Something like this:
if (have_rows('candidates')):
$total = 0;
while (have_rows('candidates')): the_row();
$position = get_sub_field('candidate_position');
if ($position == "Mayor") {
$total++;
};
endwhile;
echo $total;
endif;
Other than that, the code actually looks right. Where are you initializing $numrows and where are you checking the value? Do you get a different value using the code above?
Related Posts:
- Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
- The values of custom fields are not available functions.php
- Problem with ACF shortcode with Repeater Field in WordPress? [closed]
- ACF: how do I get the fields and its values of a specific group?
- Download PDF after CF7 form submission
- How to create an ACF shortcode with Repeater Field in WordPress? [duplicate]
- HTML Special Characters in URL string [closed]
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- Delete images from media library when user deletes an image from ACF Gallery
- Advance custom fields variable with if statement & Function
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- Page returning ID from array, how to return the correct values for post in acf wordpress
- ACF Date fileds to Age Convert [closed]
- Custom WordPress Function – Adding items from Foreach Loop into an array and Updating Field based on array of IDs (ACF + WooCommerce)
- Creating posts with php-script + csv
- ACF number less than comparison not working
- “acf/load_field” Critical error upon saving/updating WooCommerce products [closed]
- Put ACF function output code the_terms
- How to set and use global variables? Or why not to use them at all
- Is it possible to disable a function of a parent theme?
- Hide old attachments from wp media library
- PHP – redirect https to http and www to non-www
- How to overwrite youtube embed?
- Enqueue Javascript Correctly for 3.5
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- Add footer.php to WordPress child theme
- Need to get specific data from array
- Restrict WordPress File Type Uploads by User Type
- Click loads template via ajax
- Generating add_settings_section() calls dynamically
- Sort registered users by post count? (inside admin dashboard)
- How to change a public function inside a class of a plugin?
- Function set default image when image not present
- Importing hard coded custom field into acf field
- Adding country tags automatically
- WooCommerce – Reset quantity input field when variation changes
- Query all posts of a custom taxonomy term
- Automatically remove a canceled order in Woocommerce
- Trying to establish connection to External Database
- How to remove the cufon script from Dzonia Lite theme [closed]
- Login/logout in header
- How to put “Read more” link in Custom Excerpt inside p tag?
- Error when adding excerpt to the content through functions.php
- Add data attribute to each li in menu
- Get users that likes the post
- How to abort saving data in save_extra_profile_fields function WordPress?
- Slick + PHP + ACF + JQuery slide reveal not working
- Get the date of the className or classID
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- Exclude category
- Security for data obtained from the database
- What exactly do this function declared into functions.php file of a WP theme?
- Display Data in Table from External Database in WP using Shortcodes
- How to check if a Customizer setting is set?
- Custom Pagination is Broken
- Remove item in Checkout
- How to use the checked() function to check for a non-empty var
- Defining multiple categories for showing latest posts
- Pagination Not Working (pages duplicating content)
- Custom functions for string data calculations
- How are these PHP functions applied to a specific page in WordPress?
- How to display already created menus via php?
- How to store checkbox data for individual users?
- Grabbing Image name From Product Image Gallery
- “pre_get_posts” orderby custom date field in different format?
- Reliable way to add nonce to HTTP Header in WordPress?
- Trying to update Woocommerce meta values
- Cant get blog name with get_option
- php code for outputting a custom page in my account
- ssl redirect function is not working
- Hide specific shipping methode depending on day and time of day
- Adding custom field to product category and show it to shop/category shop page
- Extra editor on top of default in Custom Post Type
- How do I fix Undefined variable using $_POST in function?
- Pagination 404 error(I have refreshed the permalinks and tried several previous options)
- How Can I Display the Last Modified Date for User Profiles on WordPress?
- Add element after navigation element title don’t works like I expect
- How to auto-generate random numbers in username?
- Get Billing Email from WooCommece Checkout and Pass to Fullstory JS
- How to delete specific element when it is not homepage?
- How to add a custom class for iframe by embed_oembed_html
- remove public static function wp_link_dialog()
- Find the method which AJAX GET calls
- How can I include tags in wordpress search without a plugin
- How can I display a query in a page?
- Using catch_that_image() for galleries?
- Get category id for a custom category and display it in a class
- Conditional Content Display
- Password form redirection to belonging post
- Trouble using wordpress functions in a pop-up modal form
- admin-ajax.php loading many times
- php “use” not working in template [closed]
- How to add margin underneath woocommerce total price amount -> productpages
- Whats wrong with my code? Need To add String to shortcode? [closed]
- Load slideshow.css file only if Slideshow is checked / on
- add if statement to the featured image
- Can I associate a custom post type with another custom post type?
- How to get ACF field to show up on all posts on front end?
- Add_filter just custom page types