Getting Access To Custom Posts Data

Problem

In WordPress you have created s custom post type to manage special data, and you would like to render the custom post entries in your project.

Solution

You can use the post binder ({{posts…}}) and pass a parameter post_type. The posts binder will allow you to request posts from the database and adding the parameter post_type, followed by the slug of the post type, it will filter out posts that are different than the posts that you wish to request.

Examples

Render a list of custom posts titles

/* assuming you have a custom post type "event" */
{{posts assign_to="my_events" post_type="event"}}
<ul>
    <h2>Events</h2>
    {{foreach $my_events.data as $event}}
    <li>Name: {{$event.post_title}}<br/>
        Description: {{$event.post_content}}<br/>
        <a href="{{$event.post_permalink}}">View Details</a>
    </li>
    {{/foreach}}
</ul>

 

 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *