Help Center

How to Pull Posts Meta Field Data for the Current CPT Post

Discover how to get the data from the “Posts” meta field for the current post with the help of the JetEngine plugin for WordPress websites.

Before you start, check the tutorial requirements:

  • Elementor (Free version), Block editor (Gutenberg), or Bricks

  • JetEngine plugin installed and activated

In this tutorial, we will focus on two cases: pulling the “Posts” meta field data from the current post and from the Options Page.

Get Data From the “Posts” Meta Field of the Current Post

This method involves creating a “Posts” meta field inside the Custom Post Type, which aims to display the selected posts on the Single post. Let’s walk through the setup process step by step.

Adjust the “Posts” meta field

First of all, we need to add the “Posts” meta field to the post type. For that, proceed to WordPress Dashboard > JetEngine > Post Types, click the “Add New” button or “Edit” the already existing post type. You can check the details on setting up a new CPT from our How to Create a Custom Post Type tutorial. In our case, we will add the “Posts” meta field to the “Departments” CPT.

click the edit button for cpt

On the newly appeared page, scroll down to the Meta fields tab and click the “New Meta Field” button. 

Fill out the Label and select the “Posts” option in the Field Type drop-down. In the Search in post types field, we choose the Post Type to get the posts from (in our case, it is a “Doctors” post type). Next, we enable the Multiple toggle as well.

posts meta field added to cpt

When you are done with the settings, click the “Update Post Type” button. 

Now we need to add the values to the posts. From the WordPress Dashboard, proceed to the needed post type and either click the “Add Page” button or “Edit” the existing post.

click the edit post button

Add the needed posts to the field and click the “Save” button once you are ready.

values are added to the posts field

Set up a custom query

Now, we need to create a Posts Custom Query to get the posts we have just added to the “Posts” meta field. 

Proceed to the WordPress Dashboard > JetEngine > Query Builder and click the “Add New” button. 

Add the Name for the query and keep the “Posts Query” option in the Query Type field. 

In the General tab, select the needed CPT in the Post Type field (in our case, it is “Doctors”).

post type selected in query settings

Then, open the Post & Page tab and click the “Dynamic Tag” icon next to the Post In field. 

Select the “Current meta value as string” option from the dropdown.

In the newly appeared pop-up, put the post meta field’s name in the Meta field input. Click the “Apply” button.

“current meta value as string” option is selected for posts in field

Click the “Add Query” button.

Display the data from the posts field on the single post

Let’s proceed to the Single Post template, where the “Posts” field data should be displayed. The settings’ details can be checked in the How to Create Archive and Single Templates for Custom Post Type tutorial. 

Make sure that the Listing Template for the Post Type was previously created. 

Add the Listing Grid widget to the template, and after setting all the basic fields in the General tab, open the Custom Query tab and enable the Use Custom Query toggle.

Select the Custom Query you have just created in the newly appeared dropdown.

custom query applied to listing grid

Click the “Publish” button once you are ready with the settings.

Check the result

When we proceed to the frontend of the Single post, we see the posts selected in the “Posts” meta field.

posts meta field’s data is displayed on the single post frontend

Get Data From the “Posts” Meta Field From the Options Page

This way explains how to pull the “Posts” meta field’s data when the field is added to the Options Page. The value will be displayed on the Single post of the CPT.

Set up the “Posts” meta field on the options page

We start by adding the “Posts” meta field to the Options Page. Proceed to the WordPress Dashboard > JetEngine > Options Pages > Add New. Here, you can add the “Posts” meta field to the Options Page or edit the existing one.

add new or edit the existing options page

When you are done with the settings in the General tab, proceed to the Fields. Click the “New Field” button. 

Enter the desired Label and choose “Posts” from the Field Type drop-down menu. In the Search in post types field, select the post type you want to retrieve posts from — in this example, it’s the “Doctors” post type. You can also enable the Multiple toggle as we did.

posts meta field added to the options page

Once you’ve configured the settings, click the “Add Page”  button to save the changes.

Now we can open the newly created Options Page and add values to the “Posts” meta field.

add values to the posts field on the options page

Click the “Save” button when you are ready with the other settings.

Create a custom query

Next, we need to create a Posts Custom Query to fetch the posts we’ve just added to the “Posts” meta field.

Navigate to WordPress Dashboard > JetEngine > Query Builder, and click the “Add New” button.

Give your query a Name and leave “Posts Query” selected in the Query Type field.

Under the General tab, choose the relevant CPT in the Post Type field — in this case, it’s “Doctors.”

post type selected in the second query settings

Next, switch to the Post & Page tab and click the “Dynamic Tag” icon next to the Post In field.

From the dropdown, choose the “Option value” option. In the pop-up that appears, select the name of the post meta field in the Option input.

“option value” option is selected for posts in field

Finally, click the “Add Query” button to save it.

Pull the data from the “Posts” field of the options page on the single post

Now, let’s move on to the Single Post template, where the “Posts” field data will be displayed.

Before you begin, ensure that the Listing Template for the post type has already been created.

Add a Listing Grid widget to the template. Once you’ve configured the basic fields in the General tab, switch to the Custom Query tab and enable the Use Custom Query toggle.

In the dropdown that appears, select the Custom Query you just created.

custom query applied to listing grid to display data from the posts field from the options page

When you’re done adjusting the settings, click the “Publish” button.

Check the result

When you visit the frontend of the Single Post, you’ll see the posts that were selected in the “Posts” meta field on the Options Page.

posts meta field’s data from the options page is displayed on the single post frontend

Now you know how to get the data from the “Posts” meta field for the current post from the current post and from the Options Page with the help of the JetEngine plugin for WordPress websites.

Was this article helpful?
YesNo

Need help?

Ask Facebook community

Get answers from 30K+ Crocoblock Community experts from all over the world.

Start a live chat

Ask question to support agent and share its details via chat messages.