0

Someone was kind enough to provide me the following code to replace the no entries text in gravityview with shortcode for a gravity form.... but I can't quite figure out how to make that variable?

I'm working with 4 forms (and consequently views), and need to display the form if the user does not have a preexisting entry (view is filtered to show only their entries) How can I replace the static ID of the gravityform in the code below with a variable for whatever form the view is supposed to be pulling from?

Gravityview and Gravityforms are both on github if you need to see their sources.

add_filter('gravitview_no_entries_text', 'custom_gravitview_no_entries_text' );

/**
 * Replace the "No entries" text with form output
 */
function custom_gravitview_no_entries_text( $text = '' ) {
    return do_shortcode( '[gravityform id=1]' );
}

The ID would be of the form that the code is showing in place of... which is dependent on the page. Of course, being WordPress, it's all one PHP page that displays based on url. For example, the page "Application" is supposed to display View1, but there's no data for View1 to display, so this code then replaces View1 with Form1.

1 Answer 1

0

I know this is an old question... but... I just discovered it while fighting the same problem. The solution ended up being pretty simple: Doublequotes are needed around the ID=!

So in this example the working solution just needs:

return do_shortcode( '[gravityform id="1"]' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.