Wordpress - Simple fields, custom posts


Creating Simple Fields

You can create simple fields under Settings / Simple Fields (after you have enabled the Simple Field plugin). Here are the steps:

  1. Create a Field Group
  2. Create a Post Connector
  3. Set the Post Type Defaults to your connector

If you need additional post types, see Creating Custom Post types below.

You can also import/export simple field settings. Here’s a typical setup for SEO and OG tags.

Displaying Simple Field values

Simple field values are stored in the {{wp.post.simplefield}} property of posts.

There are two types of simple fields: single and repeatable.

For single simple fields, just use the slugs for the group and field as such:

{{wp.post.simplefield.meta_tags.meta_title}}

For repeatable simple fields, you can do the same, but you’ll need to loop your way through it:

{% foreach wp.post.simplefield.related_items as related_item %}
  <h2>{{related_item.title}}</h2>
  {{related_item.text}}
{% endforeach %}

Fetch posts by Simple Field value

You can use the Simple Field plugin to add additional meta data to your posts and pages. Sometimes you may need to list posts or sort posts based on this meta data. You can use the WP_Query and WP_Meta_Query class to specify complex queries, but here are two basic examples.

You can pick the simplefield ID (the long variable “_simple_fields_fieldGroupID_2_fieldID_0_numInSet_0” in the example) from here if you click on “Show custom field keys” id post editor:

First, let’s look at how to fetch data based on Simple Field data:
Second, let’s see how we can sort posts based on Simple Field data:

Creating Custom Posts

Custom post types allow you to create special post type admin user interfaces. Here are the steps to create a custom post type:

  1. turn on Custom Post Type UI wordpress plugin
  2. add new CPT UI, set preferences and remember to chose an ID for “Post Type Name”
  3. set advanced options, for example typically you will use “Exclude From Search” true
  4. create simple field field groups, post connectors, and set the post connector defaults to your new post type

Fetch Custom Posts

By default, WordPress will return just standard posts when you perform a query.

To query for your new custom post type, you’ll need to filter for it:

$this->zajlib->variable->customposts = WpPost::fetch()->filter('post_type', 'PostTypeName');
Outlast Web & Mobile Development (c) 2023 | Privacy Policy |