I have a page that lists all live posts on a single page, with an edit link next to each one of them. The edit link to a post looks like this:


where 3329 is the {post_id}. Clicking the edit link takes the user to a form with shortcode:

[gravityforms id="1" update="xx"]

Is there a way i can update "xx" with 3329? Via PHP, I tried this:

$post_ID = get_query_var( 'pid' );

echo do_shortcode( '[gravityform id="2" update="' . $post_ID . '"]' );

but it doesn't seem to work. Any idea where I'm failing?

1 Answer 1


To use get_query_var, you must first register the query variable with the query_vars filter.

add_filter( 'query_vars', 'wpse251014_query_vars' );
function wpse251014_query_vars( $query_vars ) {
    $query_vars[] = 'pid';
    return $query_vars;

Reference: get_query_var

  • Hmm, that doesn't seem to work. Is it my shortcode that is causing the problem? <?php add_filter( 'query_vars', 'wpse251014_query_vars' ); function wpse251014_query_vars( $query_vars ) { $query_vars[] = 'pid'; return $query_vars; } $post_ID = get_query_var( 'pid' ); echo do_shortcode( '[gravityform id="11" update="' . $post_ID . '" title="false" description="false"]' ); ?>
    – chainznanz
    Commented Jan 2, 2017 at 15:27

Your Answer

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

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