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

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

Custom post type category not displaying category ID

get_the_category retrieve array of post categories. This tag may be used outside the loop by passing a post id as the parameter. The syntax is $categories = get_the_category( $post_id ); // Outside the loop // OR $categories = get_the_category( ); // Inside the loop Note: This function only returns results from the default “category” taxonomy. … Read more

Using featured image of blog archive page

You need to grab the ID of the page you’ve set as your Posts page in Settings > Reading in order to access its properties. To do that, check for the page_for_posts option, which returns the ID: $page_for_posts = get_option( ‘page_for_posts’ ); if ($page_for_posts && has_post_thumbnail($page_for_posts) { $thumb_id = get_post_thumbnail_id( $page_for_posts); $url = wp_get_attachment_url( $thumb_id … Read more