Pull Post Title from Post Id

I created a custom looper to pull a post ID from a table. The post ID is showing up correctly see below.

We’re able to grab the post ID with this looper code. {{ looper.field({"key":"post"}) }}

How can I show the title of the posts using the post ID on this text field? I’ve tried dynamic fields and WPquery, but have had no luck.

Hello @OctoCog,

Thank you for the inquiry.

You can try this twig template:

{% set post_id = looper.field({"key": "post"}) %}
{% set post = get_post(post_id) %}

<h1>{{ post.title }}</h1>
<p>{{ post.content }}</p> 

Please check this link for more info: https://theme.co/docs/twig

Best regards.

@Ismael Thank you, this is very helpful. I went through the documentation and set up the Twig template. I input the Twig template value into the text field, but nothing is showing up.

This is the Twig (Include) template I added to my text element content.
{% include 'cs-template:post-title-from-rmp' %}

Am I supposed to display the content in some other way?

Hey @OctoCog,

Try this first:

{{ post.title({"post":" {{ looper.field({"key":"post"}) }} "}) }}

Hope this helps.

@ruenel Thank you for the suggestion, but this did not work at pulling the post title.

Thank you for the info.

Please create a test page and provide the login details in the secure note so we can check the modification further.

Warm regards.

@Ismael The test page has been created and you’ll find the login details in the secure note.

Thank you for the info.

We edited the Text element and adjusted the Twig template a bit.

{% set cpost_id = looper.field({"key": "post"}) %}<br />
{% set cpost = get_post(cpost_id) %}</p>
{{cpost.post_title}}

Let us know if you need more info.

Warm regards.

@Ismael Thank you, that worked! My next question is how would I grab the permalink from the post id?

I used this Twig code, but it’s not working.

{% set cpost_id = looper.field({"key": "post"}) %}
{% set permalink = get_the_permalink(cpost_id) %}
{{cpost.permalink}}

@Jonson That dynamic code did not work in the button URL.