Support

Account

Home Forums Front-end Issues Show custom fields, but hide empty and select fields

Solving

Show custom fields, but hide empty and select fields

  • Hi

    I am using get_field_objects loop to show all of my fields (only with data not empty ones) but it also shows some unwanted fields i.e. Logo field gives me URL of the field, How can I hide some fields in loop?

    Thanks

  • Hi @webwebby

    You can hide the fields by matching against any of the $field parameters. For example, if you wanted to hide all image fields, you could do it like so:

    
    <?php 
    
    $fields = get_field_objects();
    
    if( $fields )
    {
    	foreach( $fields as $field )
    	{
    		if( $field['type'] == 'image' )
    		{
    			continue;
    		}
    		
    		echo "<p>{$field['label']}: {$field['value']}</p>";
    		
    	}
    }
     ?>
    
  • HI @elliot

    Thanks for you help but actually it is not only about image fields, but want to filter them by field name, I want to show and hide some text & image fields so how to filter them?

    Thanks again.

  • Then just change $field['type'] == 'image' to $field['name'] == 'my_name'

  • PHP is a very powerful and simple to use language. You should first learn how to debug / print out an array ($field)

    Then you will understand how you can match if statements to the data in $field

    Thanks
    E

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

The topic ‘Show custom fields, but hide empty and select fields’ is closed to new replies.