Skip to content

Instantly share code, notes, and snippets.

@luistinygod
Last active May 1, 2020 16:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save luistinygod/9dce30ca1fd146dd31bc to your computer and use it in GitHub Desktop.
Save luistinygod/9dce30ca1fd146dd31bc to your computer and use it in GitHub Desktop.
GravityView: Removes Custom Content field content in case a certain entry's field is empty
<?php
/** Modify the content returned from the Custom Content field */
add_filter( 'gravityview/fields/custom/content_before', 'my_gv_custom_content_before', 10, 1 );
/**
* Removes the custom content field's content in case a certain entry field is empty
* Replace the MY_FIELD_ID by the field id (check it on the Gravity Forms form definition)
*
* @param string $content Custom Content field content
* @return string
*/
function my_gv_custom_content_before( $content ) {
$id = 'MY_FIELD_ID';
global $gravityview_view;
extract( $gravityview_view->field_data );
if( empty( $entry[ (string)$id ] ) ) {
return '';
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment