How can I count ACF sub_field with a certain value

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++; }; … Read more

I am trying to make a field show and save from quickedit screen

You have to register your quick edit custom box: function display_custom_quickedit_book( $column_name, $post_type ) { // it would be a good idea to add a nonce here ?> <fieldset class=”inline-edit-col-right inline-edit-book”> <div class=”inline-edit-col column-<?php echo $column_name; ?>”> <label class=”inline-edit-group”> <!– here goes your input –> </label> </div> </fieldset> <?php } add_action( ‘quick_edit_custom_box’, ‘display_custom_quickedit_book’, 10, 2 … Read more

Argument for if term-> have child?

You can use get_term_children() to check if a specific term has any children, and if yes, display the children; otherwise, display the parent”s children. So just change the if ($term->parent == 0) { to: $children = get_term_children( $term->term_id, $term->taxonomy ); if ( ! is_wp_error( $children ) && ! empty( $children ) ) { Or here’s … Read more

How to display a custom product field value of a specific category on a Woo Commerce checkout page?

Try something like this, I am unable to test this at the moment. add_action(‘woocommerce_before_calculate_totals’, ‘personalization_check_category_in_cart’); function personalization_check_category_in_cart() { // loop through all products in the Cart foreach (WC()->cart->get_cart() as $cart_item) { // if cart has category term, set variable $cat_in_cart to true if (has_term( ‘Personalize’, ‘product_cat’, $cart_item[‘product_id’])) { $product = $cart_item[‘data’]; // get product data … Read more

change title page on search result

To change document title use document_title_parts.filter. You want to apply changes only on the search page (as indicated in the title), so you should use is_search() conditional tag (or is_archive() as you suggest in the comment) and your code from php file. add_filter( ‘document_title_parts’, ‘se333744_site_title’ ); function se333744_site_title( $title ) { global $wp_query; if ( … Read more