-
Notifications
You must be signed in to change notification settings - Fork 63
Description
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:
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:
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
- Create a form with regular fields (Single Input Text, Paragraph, etc). Don't use Post Fields;
- Configure a post creation feed with the Advanced Post Creation add-on;
- Submit the form;
- Check if a Post has been created;
- Create a View for this form;
- When adding fields to the View, how would you link to that recently created post?