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
- Error Warning: Declaration of description_walker::start_el after PHP upgrade [duplicate]
- Mega Menu Walker
- Autoloading in Child Theme
- How to add a class to the attachment images
- How to call a function only once (global variable scope)
- Multiple is_page() in page.php
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- How to correct schedule my event weekly with wp_schedule_event()
- Execute a shortcode when clicking on a image
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- How can update custom meta for all posts
- Change logo based on incoming domain
- wrong php date()?
- Looking for most performant way to execute several similar WP queries within shortcodes
- How do I fetch all comments per post via WP REST API?
- PHP code inside shortcodes
- Trouble With Conditional Logic in PHP
- How do I display a user’s previous orders as a select box option on a product?
- Remove meta description on certain pages
- Image media upload metabox
- How to combine wordpress_logged_in cookies in one cookie?
- Two Different Links for Same Product – WooCommerce [closed]
- Woocommerce related product text
- esc_html_e() is not translating string in wordpress [closed]
- Limit 1 global comment per minute
- Modify custom field input data before creating a new post
- Query Pages and post excerpts dynamically
- Is there a way to conditionally check whether a WordPress post title is empty?
- Echo a function inside a function
- Advanced Custom Fields – display label and value only if value entered
- Use WordPress function in php file
- Get my site session in wordpress?
- wp_force_remove_style’ not found
- is_user_logged_in() not working in AJAX validation call
- Register a menu – Error Header
- Pagination on Custom Post
- how to save checkbox data for custom setting?
- How to keep the capability of users and disable Gutenberg editor in WordPress?
- Add product to cart for user – WC()->cart->add_to_cart [closed]
- How to create a field in customize and show that in header.php?
- Set site title & tagline with wp.config or function.php
- Shortcode to embed Edit Account form not working
- get_current_site() is undefined
- Automatically Add Page Links to Nav Menu
- blank white page when post/update/change option etc
- Function sanitize_title() does not appear to be working
- writing an unique php function to be used on my website
- Displaying Event within two given time frames
- How to prevent a function from running based on host (ie web vs local)?
- How to call custom function outside from the admin page?
- Output product category link from WP_Query
- Adding onload to body for certain pages
- Counting number of posts in multiple (sub)categories using shortcode
- Reject all malicious URL requests functions.php
- Change wordpress’ database data using ajax – how to get current user id?
- Like and Dislike Buttons on Post with Counter – Only allow one click per post per user session
- Best way to use variables in multiple functions?
- Notice: Undefined variable
- Cannot fetch posts with certain ‘product_cat’. WP_Query is empty
- How to override WooCommerce Order Item Meta with data from Cart?
- Taxonomy Child Term, Counter is staying on 0
- Detect what link user clicks and Redirect to a specific page for logged in users only
- Offset with ajax load more posts duplicates
- Get the total Author Favorited posts
- Need help with PHP functions
- Using get_theme_mod with checkbox to display content
- WordPress styling recent post
- If or/and statement advanced custom fields [closed]
- Break a WordPress function to run in patches and re-continue
- Pagenav Not appearing on custom Template
- syntax error unexpected ‘}’ at 364 line
- get_post_meta no longer working
- Highlight posts currently being edited on multiple editor site?
- Shortcode to include PHP file, pass various parameters to include?
- Why can’t I include echo inside a variable? [closed]
- Assign new post author IF another user in custom field on post transition
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- How do I change the Go To Categories link in the term_updated_messages
- WooCommerce – Show ‘Sales’ badge on variable products where only some variations have sales price [closed]
- advanced custom fields: repeater field within conditional statement [closed]
- Automatically change insurance quantity based on cart total [closed]
- /page/2/ redirect to 404
- How to pass value to add_filter wpcf7_form_tag from another function?