Display ACF if parent page has specific template

For anyone dealing with the same issue, I just needed to change: $choices[ $template_name ] = $template_name; with: $choices[ $template_filename ] = $template_name; Consider a page template Homepage (page-home.php). This way the template name Homepage will appear on the custom fields page but $rule[‘value’] will actually return page-home.php and then we can compare this with …

Read more

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

Filter Pages by Custom Field (ACF) in admin area

Try to use this code and modify the custom post name and meta key of acf and it will work. add_action( ‘restrict_manage_posts’, ‘wpse45436_admin_posts_filter_restrict_manage_posts’ ); /** * First create the dropdown /** Create the filter dropdown */ function wpse45436_admin_posts_filter_restrict_manage_posts(){ $type=”movies”; // change to custom post name. if (isset($_GET[‘movies’])) { $type = $_GET[‘movies’]; } //only add filter …

Read more