WordPress - Connections and data

The Outlast Framework {{wp.post}}

In almost all cases where you load up WordPress data you will have access to a {{wp.post}} variable which is actually an Outlast Framework WpPost (or WpPage) object. The object aims to work exactly like any other Outlast Framework model object does: you can fetch it, filter results, paginate it, create it, save it, etcetc.

It is important to know that WordPress considers everything a post whether it is a post, a page, or even an attachment (an uploaded image or document).

These are cached values so you can access them via {{wp.post.name}} for example. If you access {{wp.post.data}} it will return the native, WordPress-based wp.post object with it’s own fields. See below for more info on that.

name, title – the post’s title
id – the integer id of the post object
data – returns the native wp.post object, so you can access {{wp.post.data.post_author}} for example. See below.
permalink, url – the post’s full url, including baseurl
content – the full content of the post
excerpt – the excerpt of the post. Will contain an intro of the post content by default if the excerpt is empty. Use {{wp.post.data.post_excerpt}} if you want the real excerpt data.
template – the template id if you’re using OFW custom template for the post
photo, featured_image – the featured image as a WpAttachment object. You can use the |photo:'sizetext' filter on this or you can access the size as a property {{wp.post.featured_image.medium}}, but be sure to use a size text that is available in WordPress (by default: thumbnail (150×150), medium (300×300), large (1024×1024) or full  (whatever the image dimensions are)). You below on WpAttechment properties.
photos – a list of photos associated with the post. You can use the |photo:’sizetext’ filter on each of these items.
attachments – a list of native WordPress objects associated with the post.
parent – the parent WpPost object (if it exists).
children – a list of subpage WpPage objects (if any exist).
customfield – a list of custom fields by key so {{wp.post.customfield.name_of_custom_field}}
simplefield – a list of simple fields by key so {{wp.post.simplefield.group_slug}} (Available only if Simple Fields WordPress plugin enabled. See docs.)
categories – a list of category objects associated with the post. Each object will have these properties: ‘name’, ‘slug’, ‘parent’ (the parent id), ‘id’
tags – a list of tags associated with the post. Each object will have: ‘name’, ‘slug’, ‘id’
language – the language code of post (‘hu’) (Available if WPML plugin is turned on.)
time_create, time_edit – unix timestamp create and edit
locale – the locale code of post (‘hu_HU’) (Available if WPML plugin is turned on.)
product – the one product associated with this WordPress post. (Available if the shop plugin is enabled and uses WordPress.)

Localizing {{wp.post}}

It is worth noting that unlike Mozajik translations, you do not need to use the {{wp.post.translation.name}} to get the translated title – translations are handled by the WPML plugin and are thus stored in completely separate objects, not as connections.

The native WordPress post object

If you access the native WordPress post object via {{wp.post.data.property_name}} you have access to the following properties (as per the WordPress documentation):

  • ID (integer) The post ID
  • post_author (integer) The post author’s ID
  • post_date (string) The datetime of the post (YYYY-MM-DD HH:MM:SS)
  • post_date_gmt (string) The GMT datetime of the post (YYYY-MM-DD HH:MM:SS)
  • post_content (string) The post’s contents
  • post_title (string) The post’s title
  • post_category (integer) The post category’s ID. Note that this will always be 0 (zero) from wordpress 2.1 onwards. To determine a post’s category or categories, use get_the_category().
  • post_excerpt (string) The post excerpt
  • post_status (string) The post status (publish|pending|draft|private|static|object|attachment|inherit|future|trash)
  • comment_status (string) The comment status (open|closed|registered_only)
  • ping_status (string) The pingback/trackback status (open|closed)
  • post_password (string) The post password
  • post_name (string) The post’s URL slug
  • to_ping (string) URLs to be pinged
  • pinged (string) URLs already pinged
  • post_modified (string) The last modified datetime of the post (YYYY-MM-DD HH:MM:SS)
  • post_modified_gmt (string) The last modified GMT datetime of the post (YYYY-MM-DD HH:MM:SS)
  • post_content_filtered (string)
  • post_parent (integer) The parent post’s ID (for attachments, etc)
  • guid (string) A link to the post. Note: One cannot rely upon the GUID to be the permalink (as it previously was in pre-2.5), Nor can you expect it to be a valid link to the post. It’s merely a unique identifier, which so happens to be a link to the post at present.
  • menu_order (integer)
  • post_type (string) (post|page|attachment)
  • post_mime_type (string) Mime Type (for attachments, etc)
  • comment_count (integer) Number of comments

Creating a new WpPost

You can also create or update the WpPost object as if it were a standard Outlast Framework object. You must make sure to use the native WordPress field names though.

$post = array(
  'ID'             => [  ] //Are you updating an existing post?
  'menu_order'     => [  ] //If new post is a page, it sets the order in which it should appear in the tabs.
  'comment_status' => [ 'closed' | 'open' ] // 'closed' means no comments.
  'ping_status'    => [ 'closed' | 'open' ] // 'closed' means pingbacks or trackbacks turned off
  'pinged'         => [ ? ] //?
  'post_author'    => [  ] //The user ID number of the author.
  'post_category'  => [ array(, ) ] //post_category no longer exists, try wp_set_post_terms() for setting a post's categories
  'post_content'   => [  ] //The full text of the post.
  'post_date'      => [ Y-m-d H:i:s ] //The time post was made.
  'post_date_gmt'  => [ Y-m-d H:i:s ] //The time post was made, in GMT.
  'post_excerpt'   => [  ] //For all your post excerpt needs.
  'post_name'      => [  ] // The name (slug) for your post
  'post_parent'    => [  ] //Sets the parent of the new post.
  'post_password'  => [ ? ] //password for post?
  'post_status'    => [ 'draft' | 'publish' | 'pending'| 'future' | 'private' | custom registered status ] //Set the status of the new post.
  'post_title'     => [  ] //The title of your post.
  'post_type'      => [ 'post' | 'page' | 'link' | 'nav_menu_item' | custom post type ] //You may want to insert a regular post, page, link, a menu item or some custom post type
  'tags_input'     => [ ', , ' ] //For tags.
  'to_ping'        => [ ? ] //?
  'tax_input'      => [ array( 'taxonomy_name' => array( 'term', 'term2', 'term3' ) ) ] // support for custom taxonomies. 

You can use import or create/set/save to save the new WpPost to the database.

// Import example
WpPost::import(array('post_title'=>'Something!', 'post_content'=>'Testing this.', 'post_status'=>'publish'));
// Create, set, save example
$p = WpPost::create();
$p->set('post_title', 'Something!');
$p->set('post_content', 'Testing this.');
$p->set('post_status', 'publish');

Updating existing WpPost objects

Updating works almost the same as creating new WpPosts objects:

$p = WpPost::fetch(20);
$p->set('post_title', 'Something!');
$p->set('post_content', 'Modified body.');

WpAttachment objects

All objects in WordPress are stored as WpPosts, but some -such as images and files uploaded to a post- are also attachments. Outlast Framework uses a separate object for accessing attachment properties – this is the WpAttachment object. A featured image of post, for example, will be a WpAttachment object.

First, let’s see the properties of the WpAttachment object:

  • id (integer) The post (or rather, the attachment) ID. All WpAttachment objects are also WpPost objects.
  • parent (integer) The parent post’s ID. This is typically a standard WpPost.
  • data (object) The native WpPost object (see above). This is data for this particular WpAttachment, and not the parent WpPost object.
  • width (integer) The width of the photo.
  • height (integer) The height of the photo.
  • landscape (boolean) True if the photo is a landscape photo.
  • portrait (boolean) True if the photo is a portrait.
  • orientation (string) This is either ‘landscape’ or ‘portrait’.
  • thumbnail (string) The url of the thumbnail.
  • medium (string) The url of the medium-sized image.
  • large (string) The url of the large-sized image.
  • full (string) The url of the full-sized image.

WpAttachment objects are most often pictures. Here are some examples of how to use WpAttachments:

{{wp.post.featured_image.medium}} - the url of the medium image
{{wp.post.featured_image.orientation}} - this will be 'landscape' or 'portrait'
Outlast Web & Mobile Development (c) 2023 | Privacy Policy |