Thanks!
I was playing with it, the issue is that the “parent post” titles are not getting displayed.
You called them related posts, but they are parent posts.
You might have misunderstood something.
Let me tell you what is happening on my site:
The setup is like this:
I have default posts, like all normal blogs.
But I am fetching post type posts within these default posts, they are submitted dynamically by using the same form defined in the default post template, and after I approve the submitted post type posts, I have to assign them manually to their taxonomy (itemscategories) name, more exactly to that taxonomy name that is identic with the deafult post title where the named post type post is supposed to be displayed, because the post type posts are displayed with a grid that uses a dynamic query by matching the default post titles with the post type post taxonomy names in order to show the right post type posts in each default post.
(I must call them “post type post” and “default post”, otherwise there might be confusion, so there are 2 kinds of posts, the default posts (post type:post) are the parent posts, and the post type posts (post type: item) are the children posts that are fetched in the parent posts by the grid using the dynamic query.)
I did not manage yet to automate the post type post category assignment by Gravity forms (basically Gravity forms should look at the parent posts title [in the post where the form was embedded, same post as where the child post will be fetched], copy that string and give it as taxonomy name to the child post, automatically – is this possible?), so I have to peek into the created Gravity Forms entry and see the “embed url” of the form entry, and assign the post type post manually to the taxonomy name that matches the embed url (or default post title) name. And I do just that: I assign its taxonomy name manually before I approve the child post.
And these parent post titles (with link) are that we are trying to display alongside the child post titles.
The child post titles already are displayed just fine, using the code provided by you.
But the parent post titles are not getting displayed.
And I also got confused:
– should I assign the field to the feed that creates the post, or to the form (which I suppose is the same as to the entry)?
Because Gravity Forms creates the posts from the entries via a “feed”, and I think that those entries are also a separate post type.
However I tried to assign a custom field with the value of the embed post ID (the post where the child post is embed) to the feed, and it returns white space only.
Finally I assigned the same field to the form itself, and now the code you gave displays some old child posts titles alongside with the 3 newest child post titles.
And I think this is because you misunderstood the situation.
That’s why I described the circumstances above just to make sure.
I corrected the post type to “items” in the function code. “itemscategories” is the taxonomy name of the “items” post type.
Which post type’s ID is the “get_the_ID” of the handler code is getting?
I think it’s getting the id of the “items” post type. That seems to be ok.
And then it converts the number into the $post_id. Is this number converted into the parent post’s ID or into the hild post’s id?
(is the child post ID called “$item_id” and the parent post ID “$post_id”? )
Because that number must be converted to (or accounted as) the parent post id.
(Well now it’s to easy to understand when I read your code.)
Then the function code goes on and wants to display post titles of the post type “items” but that’s wrong, we need post titles of the post type “post”, the default post type, because those are the parent posts whose titles we need alongside the child post titles.
I think the issue is that the ‘gravity_embed_id’
// post meta value provided by Gravity Forms is accounted by the code as the ID of the child posts, not as the ID of the parent posts, of the posts where the form was embedded, as it should be.
And that’s what we need. It just need to be converted into titles with links.
So I tried to change this part of the function code
if ( 0 != count( $items )) { // avoids throwing PHP warnings if no items found
foreach ( $items as $item ) {
$list .= $item->post_title . ' ';
into this
if ( 0 != count( $post )) { // avoids throwing PHP warnings if no items found
foreach ( $posts as $post ) {
$list .= $post->post_title . ' ';
but it returns only whitespace.
So the numeric value provided by the Gravity field is the ID of the post type “post”, not “items”.
Even though that field belongs to the post type “items” (child post), it returns the ID of the post type “post”, the parent post.
My correction was not successful.
How to correct the function code so that the obtained numeric value will be accounted as ID of the post type “post”, and so that the function will finally derive and output the post titles of the post type “post” and not “items”?
Here are the 2 screenshots of my current setup:
flameshot_screenshot
flameshot_screenshot
So what is called parameter on the screenshot, you passed as “meta key”. I hope that is right…
I checked the option “Allow field to be populated dynamically”, but I don’t know if they are actually automaticaly populated without adding a hook.
But I think they are because the ID of the parent post is properly displayed in the form entry:
flameshot_screenshot
So I don’t think that I need to use a hook like this:
https://docs.gravityforms.com/using-dynamic-population/#hooks
Thanks! And thanks for telling extra advice that I did not even ask about. Have a nice evening, #stayhome.
-
This reply was modified 4 years, 7 months ago by
berry metal.
-
This reply was modified 4 years, 7 months ago by
berry metal.
-
This reply was modified 4 years, 7 months ago by
berry metal.
-
This reply was modified 4 years, 7 months ago by
berry metal.
-
This reply was modified 4 years, 7 months ago by
berry metal.
-
This reply was modified 4 years, 7 months ago by
berry metal.
-
This reply was modified 4 years, 7 months ago by
berry metal.