Support

Account

Home Forums ACF PRO If relationship field has only draft posts then hide this section Reply To: If relationship field has only draft posts then hide this section

  • 
    <?php 
    	// add to function.php
    	function acf_field_only_published_posts($query) {
    		$query->set('post_status', 'publish');
    	}
    ?>
    
    
    if (get_field('alternative_method')) {
    	// add filter to only get published posts
    	add_action('pre_get_posts', 'acf_field_only_published_posts');
    	// get field
      $alt_posts = get_field('alternative_method');
    	// remove the filter so it does not affect other queries
    	remove_filter('pre_get_posts', 'acf_field_only_published_posts');
    	
    	if (!empty($alt_posts)) {
    		
    		// the rest of code to output section here
    		
    	} // end if !empty($alt_posts)
    } // end if get_field('alternative_method')