Title: Conditional ACF fields within post layout
Last modified: April 11, 2025

---

# Conditional ACF fields within post layout

 *  Resolved [tb21](https://wordpress.org/support/users/tb21/)
 * (@tb21)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/conditional-acf-fields-within-post-layout/)
 * Hi,
 * I’ve setup a custom layout that needs to pull through ACF fields conditionally,
   so if they are blank the section won’t appear. I’m struggling to apply the condition,
   any help would be appreciated!
 *     ```wp-block-code
       function my_custom_post_layout($layout, $post_id, $filter_id, $increment_post, $arrOptions) {  	$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'medium');	$wifi = get_field('wifi');	$parking = get_field('car_park_spaces');	$disabled = get_field('disabled_parking');	$rooms = get_field('other_meeting_rooms');	$capacity = get_field('seated_capacity');	$layout  = '<div class="halldirectoryblock imageblock" style="background-image:url('.esc_url($featured_img_url).');  height: 100%;background-size:cover;background-position: center;"><a href="'.get_the_permalink($post_id).'" style="height:100%;"></a></div>';$layout .= '<div class="halldirectoryblock" style="padding: 2em;vertical-align:top;"><a href="'.get_the_permalink($post_id).'"><h3>'.get_the_title($post_id).'</h3></a><p class="capacity1">Capacity: '.$capacity.'</p><?php if($wifi) { ?><img src="/wp-content/uploads/2025/03/Wifi.svg" class="featureicon"/><?php } if($parking) { ?><img src="/wp-content/uploads/2025/03/Car-Parking.svg" class="featureicon"/><?php } if($disabled) { ?><img src="/wp-content/uploads/2025/03/Disabled-Parking.svg" class="featureicon"/><?php } if($rooms) { ?><img src="/wp-content/uploads/2025/03/Other-Meeting-Rooms.svg" class="featureicon"/><?php } ?><a href="'.get_the_permalink($post_id).'" style="float:right;"><img src="/wp-content/uploads/2025/03/Arrow.svg" style="width:24px;height:16px;" alt="Read More"></a></div>';    // $layout .= '<a class="'.esc_attr($arrOptions['class_popup']).'" data-postid="'.esc_attr($post_id).'" href="#">Open Popup</a>';     return $layout;}
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [YMC](https://wordpress.org/support/users/wssoffice21/)
 * (@wssoffice21)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/conditional-acf-fields-within-post-layout/#post-18411683)
 * Hi!
 * You will need to specify the ACF field, pass the post ID there, for example:
 *     ```wp-block-code
       $wifi = get_field('wifi', $post_id);
       ```
   
 *  Thread Starter [tb21](https://wordpress.org/support/users/tb21/)
 * (@tb21)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/conditional-acf-fields-within-post-layout/#post-18411726)
 * Hi!
 * I’ve changed this, but I still get the following in my output:
 *     ```wp-block-code
       <!--?php if($wifi) { ?--><img src="/wp-content/uploads/2025/03/Wifi.svg" class="featureicon"><!--?php } if($parking) { ?--><img src="/wp-content/uploads/2025/03/Car-Parking.svg" class="featureicon"><!--?php } if($disabled) { ?--><img src="/wp-content/uploads/2025/03/Disabled-Parking.svg" class="featureicon"><!--?php } if($rooms) { ?--><img src="/wp-content/uploads/2025/03/Other-Meeting-Rooms.svg" class="featureicon"><!--?php } ?-->
       ```
   
 *  Plugin Author [YMC](https://wordpress.org/support/users/wssoffice21/)
 * (@wssoffice21)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/conditional-acf-fields-within-post-layout/#post-18411742)
 * Study the documentation on ACF fields and the plugin in more detail. Everything
   should work correctly here if you use the hook (filter)` add_filter('ymc_post_custom_layout_545_1','
   my_custom_post_layout', 10, 5);.` See the documentation on the plugin [https://github.com/YMC-22/smart-filter](https://github.com/YMC-22/smart-filter)
 * [https://prnt.sc/5F-HnZyPdp0f](https://prnt.sc/5F-HnZyPdp0f)
 *  Thread Starter [tb21](https://wordpress.org/support/users/tb21/)
 * (@tb21)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/conditional-acf-fields-within-post-layout/#post-18414848)
 * Thanks, I managed to code a workaround by excluding the if fields from the layout.
 * One other issue I am having is the “And” condition on the Taxonomy relation only
   works across different taxonomies. When I select multiple options from within
   the same taxonomy, it performs as if it is an “Or” condition.
 *  Plugin Author [YMC](https://wordpress.org/support/users/wssoffice21/)
 * (@wssoffice21)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/conditional-acf-fields-within-post-layout/#post-18414879)
 * **Relation**
   How to select posts from specified taxonomies. Can be:AND – posts
   that are both included in the specified taxonomy terms.OR – posts that belong
   to any of the specified taxonomy terms.So this only applies if the post belongs
   to multiple taxonomies. And if the post belongs to only one taxonomies, this 
   does not affect the selection of posts in any way. Read the documentation on 
   using the global WP_Query object

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Conditional ACF fields within post layout’ is closed to new replies.

 * ![](https://ps.w.org/ymc-smart-filter/assets/icon-128x128.png?rev=3354891)
 * [YMC Filter](https://wordpress.org/plugins/ymc-smart-filter/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ymc-smart-filter/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ymc-smart-filter/)
 * [Active Topics](https://wordpress.org/support/plugin/ymc-smart-filter/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ymc-smart-filter/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ymc-smart-filter/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [YMC](https://wordpress.org/support/users/wssoffice21/)
 * Last activity: [1 year, 1 month ago](https://wordpress.org/support/topic/conditional-acf-fields-within-post-layout/#post-18414879)
 * Status: resolved