Skip to content

Create a Merge Tag to retrieve the Post ID from an Advanced Post Creation add-on feed #2306

@rafaehlers

Description

@rafaehlers

It was easy to link entries to Posts if these posts were created using Gravity Forms' Post fields, by checking these options on the field modal:

Image

However, if the Posts were created using the Advanced Post Creation add-on, this option is not present. Therefore, I end up incorrectly suggesting this workaround to a user:

Image

The problem with that is that the APC add-on does not store the {post_id} merge tag because it works with feeds, so you can have as many posts tied to a single entry as possible. More about the {post_id}

For that reason, it stores each created post ID as a separate entry meta, rather than a single post_id field.

To help with this, @bennemann created a custom shortcode that retrieves the latest post ID created by APC for a given entry:

function gk_apc_post_id( $atts ) {
	$entry_id = absint( $atts['entry_id'] ?? 0 );
	if ( ! $entry_id ) return '';

	$posts = gform_get_meta( $entry_id, 'gravityformsadvancedpostcreation_post_id' );

	return ! empty( $posts ) ? intval( end( $posts )['post_id'] ) : '';
}
add_shortcode( 'gk_apc_post_id', 'gk_apc_post_id' );

Usage: <a href="https://www.example.com/?p=[gk_apc_post_id entry_id={entry_id}]">View Post</a>

What's needed

  • We need to create a custom Merge Tag built into GravityView for this that supports the possibility of one entry having more than one post associated with it.

Steps to reproduce

  1. Create a form with regular fields (Single Input Text, Paragraph, etc). Don't use Post Fields;
  2. Configure a post creation feed with the Advanced Post Creation add-on;
  3. Submit the form;
  4. Check if a Post has been created;
  5. Create a View for this form;
  6. When adding fields to the View, how would you link to that recently created post?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions